From 0befd9ad8573e8be003fa2dbca2753c6216538ab Mon Sep 17 00:00:00 2001 From: zhiyuan <32867472+zhiyuang@users.noreply.github.com> Date: Thu, 16 Mar 2023 11:04:55 +0800 Subject: feat(expect): update toBeInstanceOf (#2396) * feat: update instanceof binding * fix: according to PR comments --- src/bun.js/bindings/bindings.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/bun.js/bindings/bindings.cpp') 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))); -- cgit v1.2.3