aboutsummaryrefslogtreecommitdiff
path: root/src/javascript/jsc/bindings/ZigGlobalObject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/javascript/jsc/bindings/ZigGlobalObject.cpp')
-rw-r--r--src/javascript/jsc/bindings/ZigGlobalObject.cpp15
1 files changed, 7 insertions, 8 deletions
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 <JavaScriptCore/AggregateError.h>
#include <JavaScriptCore/BytecodeIndex.h>
#include <JavaScriptCore/CallFrameInlines.h>
-
#include <JavaScriptCore/ClassInfo.h>
#include <JavaScriptCore/CodeBlock.h>
#include <JavaScriptCore/CodeCache.h>
@@ -23,6 +22,7 @@
#include <JavaScriptCore/IteratorOperations.h>
#include <JavaScriptCore/JSArray.h>
#include <JavaScriptCore/JSCInlines.h>
+#include <JavaScriptCore/JSCallbackConstructor.h>
#include <JavaScriptCore/JSCallbackObject.h>
#include <JavaScriptCore/JSCast.h>
#include <JavaScriptCore/JSClassRef.h>
@@ -231,13 +231,15 @@ extern "C" JSC__JSValue JSC__JSValue__makeWithNameAndPrototype(JSC__JSGlobalObje
auto& vm = globalObject->vm();
JSClassRef jsClass = reinterpret_cast<JSClassRef>(arg1);
JSClassRef protoClass = reinterpret_cast<JSClassRef>(arg2);
- JSObjectRef objectRef = JSObjectMake(reinterpret_cast<JSContextRef>(globalObject), jsClass, nullptr);
+ JSObjectRef objectRef = JSObjectMakeConstructor(reinterpret_cast<JSContextRef>(globalObject), protoClass, jsClass->callAsConstructor);
+ JSObjectRef wrappedRef = JSObjectMake(reinterpret_cast<JSContextRef>(globalObject), jsClass, nullptr);
JSC::JSObject* object = JSC::JSValue::decode(reinterpret_cast<JSC__JSValue>(objectRef)).getObject();
+ JSC::JSObject* wrapped = JSC::JSValue::decode(reinterpret_cast<JSC__JSValue>(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<JSC__JSValue>(JSObjectMake(reinterpret_cast<JSContextRef>(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<GlobalPropertyInfo> 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<JSC::JSCallbackObject<JSNonFinalObject>*>(vm(), JSC::JSValue::decode(constructors[i]).asCell()->getObject());
- if (JSObject* prototype = object->classRef()->prototype(this))
- object->setPrototypeDirect(vm(), prototype);
+ auto* object = JSC::jsDynamicCast<JSC::JSCallbackConstructor*>(vm(), JSC::JSValue::decode(constructors[i]).asCell()->getObject());
extraStaticGlobals.uncheckedAppend(
GlobalPropertyInfo { JSC::Identifier::fromString(vm(), object->get(this, vm().propertyNames->name).toWTFString(this)),