From b54a51adb96b3eea6aacff4f83f3ac39ddbc933e Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sat, 26 Mar 2022 15:12:10 -0700 Subject: fix `instanceof` checks for classes --- src/javascript/jsc/bindings/ZigGlobalObject.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/javascript/jsc/bindings/ZigGlobalObject.cpp') diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.cpp b/src/javascript/jsc/bindings/ZigGlobalObject.cpp index 3a7a8e72b..ad1c23da5 100644 --- a/src/javascript/jsc/bindings/ZigGlobalObject.cpp +++ b/src/javascript/jsc/bindings/ZigGlobalObject.cpp @@ -5,7 +5,6 @@ #include #include #include - #include #include #include @@ -23,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -231,13 +231,15 @@ extern "C" JSC__JSValue JSC__JSValue__makeWithNameAndPrototype(JSC__JSGlobalObje auto& vm = globalObject->vm(); JSClassRef jsClass = reinterpret_cast(arg1); JSClassRef protoClass = reinterpret_cast(arg2); - JSObjectRef objectRef = JSObjectMake(reinterpret_cast(globalObject), jsClass, nullptr); + JSObjectRef objectRef = JSObjectMakeConstructor(reinterpret_cast(globalObject), protoClass, jsClass->callAsConstructor); + JSObjectRef wrappedRef = JSObjectMake(reinterpret_cast(globalObject), jsClass, nullptr); JSC::JSObject* object = JSC::JSValue::decode(reinterpret_cast(objectRef)).getObject(); + JSC::JSObject* wrapped = JSC::JSValue::decode(reinterpret_cast(wrappedRef)).getObject(); + object->setPrototypeDirect(vm, wrapped); JSString* nameString = JSC::jsNontrivialString(vm, Zig::toString(*visibleInterfaceName)); object->putDirect(vm, vm.propertyNames->name, nameString, JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum); object->putDirect(vm, vm.propertyNames->toStringTagSymbol, nameString, JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly); - object->putDirect(vm, vm.propertyNames->prototype, JSC::JSValue::decode(reinterpret_cast(JSObjectMake(reinterpret_cast(globalObject), protoClass, nullptr))), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete); return JSC::JSValue::encode(JSC::JSValue(object)); } @@ -590,17 +592,14 @@ static JSC_DEFINE_HOST_FUNCTION(functionReportError, // and any other objects available globally. void GlobalObject::installAPIGlobals(JSClassRef* globals, int count) { - auto clientData = Bun::clientData(vm()); size_t constructor_count = 0; JSC__JSValue const* constructors = Zig__getAPIConstructors(&constructor_count, this); WTF::Vector extraStaticGlobals; - extraStaticGlobals.reserveCapacity((size_t)count + constructor_count + 3 + 9); + extraStaticGlobals.reserveCapacity((size_t)count + constructor_count + 3 + 10); int i = 0; for (; i < constructor_count; i++) { - auto* object = JSC::jsDynamicCast*>(vm(), JSC::JSValue::decode(constructors[i]).asCell()->getObject()); - if (JSObject* prototype = object->classRef()->prototype(this)) - object->setPrototypeDirect(vm(), prototype); + auto* object = JSC::jsDynamicCast(vm(), JSC::JSValue::decode(constructors[i]).asCell()->getObject()); extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { JSC::Identifier::fromString(vm(), object->get(this, vm().propertyNames->name).toWTFString(this)), -- cgit v1.2.3