aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/bindings.cpp
diff options
context:
space:
mode:
authorGravatar zhiyuan <32867472+zhiyuang@users.noreply.github.com> 2023-03-16 11:04:55 +0800
committerGravatar GitHub <noreply@github.com> 2023-03-15 20:04:55 -0700
commit0befd9ad8573e8be003fa2dbca2753c6216538ab (patch)
tree168011aea064edd7a9ba2ad459ebbbd56d0286b4 /src/bun.js/bindings/bindings.cpp
parent79a05d50ad58059f6cea973deb59e8fab4e50e31 (diff)
downloadbun-0befd9ad8573e8be003fa2dbca2753c6216538ab.tar.gz
bun-0befd9ad8573e8be003fa2dbca2753c6216538ab.tar.zst
bun-0befd9ad8573e8be003fa2dbca2753c6216538ab.zip
feat(expect): update toBeInstanceOf (#2396)
* feat: update instanceof binding * fix: according to PR comments
Diffstat (limited to 'src/bun.js/bindings/bindings.cpp')
-rw-r--r--src/bun.js/bindings/bindings.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index 9e0857578..f273bca46 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -3791,6 +3791,27 @@ bool JSC__JSValue__isConstructor(JSC__JSValue JSValue0)
return value.isConstructor();
}
+bool JSC__JSValue__isInstanceOf(JSC__JSValue JSValue0, JSC__JSGlobalObject* globalObject, JSC__JSValue JSValue1)
+{
+ VM& vm = globalObject->vm();
+
+ auto scope = DECLARE_CATCH_SCOPE(vm);
+
+ JSValue jsValue = JSValue::decode(JSValue0);
+ JSValue jsValue1 = JSValue::decode(JSValue1);
+ if (UNLIKELY(!jsValue1.isObject())) {
+ return false;
+ }
+ JSObject* jsConstructor = JSC::asObject(jsValue1);
+ if (UNLIKELY(!jsConstructor->structure()->typeInfo().implementsHasInstance()))
+ return false;
+ bool result = jsConstructor->hasInstance(globalObject, jsValue);
+
+ RETURN_IF_EXCEPTION(scope, false);
+
+ return result;
+}
+
extern "C" JSC__JSValue JSC__JSValue__createRopeString(JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSGlobalObject* globalObject)
{
return JSValue::encode(JSC::jsString(globalObject, JSC::JSValue::decode(JSValue0).toString(globalObject), JSC::JSValue::decode(JSValue1).toString(globalObject)));