diff options
-rw-r--r-- | src/bun.js/bindings/JSSink.cpp | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/JSSink.h | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h | 44 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h | 148 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 75 | ||||
-rw-r--r-- | src/bun.js/scripts/generate-classes.ts | 10 | ||||
-rw-r--r-- | test/bun.js/globals.test.js | 19 |
7 files changed, 180 insertions, 120 deletions
diff --git a/src/bun.js/bindings/JSSink.cpp b/src/bun.js/bindings/JSSink.cpp index fc77113ac..cc1bfbbac 100644 --- a/src/bun.js/bindings/JSSink.cpp +++ b/src/bun.js/bindings/JSSink.cpp @@ -1,6 +1,6 @@ // AUTO-GENERATED FILE. DO NOT EDIT. -// Generated by 'make generate-sink' at 2022-08-19T01:36:01.093Z +// Generated by 'make generate-sink' at 2022-08-19T05:47:23.230Z // To regenerate this file, run: // // make generate-sink diff --git a/src/bun.js/bindings/JSSink.h b/src/bun.js/bindings/JSSink.h index 32c0ff021..2c104a975 100644 --- a/src/bun.js/bindings/JSSink.h +++ b/src/bun.js/bindings/JSSink.h @@ -1,6 +1,6 @@ // AUTO-GENERATED FILE. DO NOT EDIT. -// Generated by 'make generate-sink' at 2022-08-19T01:36:01.092Z +// Generated by 'make generate-sink' at 2022-08-19T05:47:23.227Z // #pragma once diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h index da5480541..c7b1fa75a 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h @@ -1,44 +1,66 @@ JSC::Structure* JSSHA1Structure() { return m_JSSHA1.getInitializedOnMainThread(this); } JSC::JSObject* JSSHA1Constructor() { return m_JSSHA1.constructorInitializedOnMainThread(this); } JSC::JSValue JSSHA1Prototype() { return m_JSSHA1.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSSHA1; + JSC::LazyClassStructure m_JSSHA1; + bool hasJSSHA1SetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSSHA1SetterValue; JSC::Structure* JSMD5Structure() { return m_JSMD5.getInitializedOnMainThread(this); } JSC::JSObject* JSMD5Constructor() { return m_JSMD5.constructorInitializedOnMainThread(this); } JSC::JSValue JSMD5Prototype() { return m_JSMD5.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSMD5; + JSC::LazyClassStructure m_JSMD5; + bool hasJSMD5SetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSMD5SetterValue; JSC::Structure* JSMD4Structure() { return m_JSMD4.getInitializedOnMainThread(this); } JSC::JSObject* JSMD4Constructor() { return m_JSMD4.constructorInitializedOnMainThread(this); } JSC::JSValue JSMD4Prototype() { return m_JSMD4.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSMD4; + JSC::LazyClassStructure m_JSMD4; + bool hasJSMD4SetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSMD4SetterValue; JSC::Structure* JSSHA224Structure() { return m_JSSHA224.getInitializedOnMainThread(this); } JSC::JSObject* JSSHA224Constructor() { return m_JSSHA224.constructorInitializedOnMainThread(this); } JSC::JSValue JSSHA224Prototype() { return m_JSSHA224.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSSHA224; + JSC::LazyClassStructure m_JSSHA224; + bool hasJSSHA224SetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSSHA224SetterValue; JSC::Structure* JSSHA512Structure() { return m_JSSHA512.getInitializedOnMainThread(this); } JSC::JSObject* JSSHA512Constructor() { return m_JSSHA512.constructorInitializedOnMainThread(this); } JSC::JSValue JSSHA512Prototype() { return m_JSSHA512.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSSHA512; + JSC::LazyClassStructure m_JSSHA512; + bool hasJSSHA512SetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSSHA512SetterValue; JSC::Structure* JSSHA384Structure() { return m_JSSHA384.getInitializedOnMainThread(this); } JSC::JSObject* JSSHA384Constructor() { return m_JSSHA384.constructorInitializedOnMainThread(this); } JSC::JSValue JSSHA384Prototype() { return m_JSSHA384.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSSHA384; + JSC::LazyClassStructure m_JSSHA384; + bool hasJSSHA384SetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSSHA384SetterValue; JSC::Structure* JSSHA256Structure() { return m_JSSHA256.getInitializedOnMainThread(this); } JSC::JSObject* JSSHA256Constructor() { return m_JSSHA256.constructorInitializedOnMainThread(this); } JSC::JSValue JSSHA256Prototype() { return m_JSSHA256.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSSHA256; + JSC::LazyClassStructure m_JSSHA256; + bool hasJSSHA256SetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSSHA256SetterValue; JSC::Structure* JSSHA512_256Structure() { return m_JSSHA512_256.getInitializedOnMainThread(this); } JSC::JSObject* JSSHA512_256Constructor() { return m_JSSHA512_256.constructorInitializedOnMainThread(this); } JSC::JSValue JSSHA512_256Prototype() { return m_JSSHA512_256.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSSHA512_256; + JSC::LazyClassStructure m_JSSHA512_256; + bool hasJSSHA512_256SetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSSHA512_256SetterValue; JSC::Structure* JSTextDecoderStructure() { return m_JSTextDecoder.getInitializedOnMainThread(this); } JSC::JSObject* JSTextDecoderConstructor() { return m_JSTextDecoder.constructorInitializedOnMainThread(this); } JSC::JSValue JSTextDecoderPrototype() { return m_JSTextDecoder.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSTextDecoder; + JSC::LazyClassStructure m_JSTextDecoder; + bool hasJSTextDecoderSetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSTextDecoderSetterValue; JSC::Structure* JSRequestStructure() { return m_JSRequest.getInitializedOnMainThread(this); } JSC::JSObject* JSRequestConstructor() { return m_JSRequest.constructorInitializedOnMainThread(this); } JSC::JSValue JSRequestPrototype() { return m_JSRequest.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSRequest; + JSC::LazyClassStructure m_JSRequest; + bool hasJSRequestSetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSRequestSetterValue; JSC::Structure* JSResponseStructure() { return m_JSResponse.getInitializedOnMainThread(this); } JSC::JSObject* JSResponseConstructor() { return m_JSResponse.constructorInitializedOnMainThread(this); } JSC::JSValue JSResponsePrototype() { return m_JSResponse.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_JSResponse;
\ No newline at end of file + JSC::LazyClassStructure m_JSResponse; + bool hasJSResponseSetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_JSResponseSetterValue;
\ No newline at end of file diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h index eca66eb15..d8d3e7f9f 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h +++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h @@ -1,83 +1,95 @@ -void GlobalObject::initGeneratedLazyClasses() { +void GlobalObject::initGeneratedLazyClasses() +{ m_JSSHA1.initLater( - [](LazyClassStructure::Initializer& init) { - init.setPrototype(WebCore::JSSHA1::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); - init.setStructure(WebCore::JSSHA1::createStructure(init.vm, init.global, init.prototype)); - init.setConstructor(WebCore::JSSHA1Constructor::create(init.vm, init.global, WebCore::JSSHA1Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA1Prototype*>(init.prototype))); - }); + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSSHA1::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSSHA1::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSSHA1Constructor::create(init.vm, init.global, WebCore::JSSHA1Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA1Prototype*>(init.prototype))); + }); m_JSMD5.initLater( - [](LazyClassStructure::Initializer& init) { - init.setPrototype(WebCore::JSMD5::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); - init.setStructure(WebCore::JSMD5::createStructure(init.vm, init.global, init.prototype)); - init.setConstructor(WebCore::JSMD5Constructor::create(init.vm, init.global, WebCore::JSMD5Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSMD5Prototype*>(init.prototype))); - }); + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSMD5::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSMD5::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSMD5Constructor::create(init.vm, init.global, WebCore::JSMD5Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSMD5Prototype*>(init.prototype))); + }); m_JSMD4.initLater( - [](LazyClassStructure::Initializer& init) { - init.setPrototype(WebCore::JSMD4::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); - init.setStructure(WebCore::JSMD4::createStructure(init.vm, init.global, init.prototype)); - init.setConstructor(WebCore::JSMD4Constructor::create(init.vm, init.global, WebCore::JSMD4Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSMD4Prototype*>(init.prototype))); - }); + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSMD4::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSMD4::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSMD4Constructor::create(init.vm, init.global, WebCore::JSMD4Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSMD4Prototype*>(init.prototype))); + }); m_JSSHA224.initLater( - [](LazyClassStructure::Initializer& init) { - init.setPrototype(WebCore::JSSHA224::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); - init.setStructure(WebCore::JSSHA224::createStructure(init.vm, init.global, init.prototype)); - init.setConstructor(WebCore::JSSHA224Constructor::create(init.vm, init.global, WebCore::JSSHA224Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA224Prototype*>(init.prototype))); - }); + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSSHA224::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSSHA224::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSSHA224Constructor::create(init.vm, init.global, WebCore::JSSHA224Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA224Prototype*>(init.prototype))); + }); m_JSSHA512.initLater( - [](LazyClassStructure::Initializer& init) { - init.setPrototype(WebCore::JSSHA512::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); - init.setStructure(WebCore::JSSHA512::createStructure(init.vm, init.global, init.prototype)); - init.setConstructor(WebCore::JSSHA512Constructor::create(init.vm, init.global, WebCore::JSSHA512Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA512Prototype*>(init.prototype))); - }); + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSSHA512::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSSHA512::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSSHA512Constructor::create(init.vm, init.global, WebCore::JSSHA512Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA512Prototype*>(init.prototype))); + }); m_JSSHA384.initLater( - [](LazyClassStructure::Initializer& init) { - init.setPrototype(WebCore::JSSHA384::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); - init.setStructure(WebCore::JSSHA384::createStructure(init.vm, init.global, init.prototype)); - init.setConstructor(WebCore::JSSHA384Constructor::create(init.vm, init.global, WebCore::JSSHA384Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA384Prototype*>(init.prototype))); - }); + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSSHA384::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSSHA384::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSSHA384Constructor::create(init.vm, init.global, WebCore::JSSHA384Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA384Prototype*>(init.prototype))); + }); m_JSSHA256.initLater( - [](LazyClassStructure::Initializer& init) { - init.setPrototype(WebCore::JSSHA256::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); - init.setStructure(WebCore::JSSHA256::createStructure(init.vm, init.global, init.prototype)); - init.setConstructor(WebCore::JSSHA256Constructor::create(init.vm, init.global, WebCore::JSSHA256Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA256Prototype*>(init.prototype))); - }); + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSSHA256::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSSHA256::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSSHA256Constructor::create(init.vm, init.global, WebCore::JSSHA256Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA256Prototype*>(init.prototype))); + }); m_JSSHA512_256.initLater( - [](LazyClassStructure::Initializer& init) { - init.setPrototype(WebCore::JSSHA512_256::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); - init.setStructure(WebCore::JSSHA512_256::createStructure(init.vm, init.global, init.prototype)); - init.setConstructor(WebCore::JSSHA512_256Constructor::create(init.vm, init.global, WebCore::JSSHA512_256Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA512_256Prototype*>(init.prototype))); - }); + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSSHA512_256::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSSHA512_256::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSSHA512_256Constructor::create(init.vm, init.global, WebCore::JSSHA512_256Constructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSSHA512_256Prototype*>(init.prototype))); + }); m_JSTextDecoder.initLater( - [](LazyClassStructure::Initializer& init) { - init.setPrototype(WebCore::JSTextDecoder::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); - init.setStructure(WebCore::JSTextDecoder::createStructure(init.vm, init.global, init.prototype)); - init.setConstructor(WebCore::JSTextDecoderConstructor::create(init.vm, init.global, WebCore::JSTextDecoderConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSTextDecoderPrototype*>(init.prototype))); - }); + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSTextDecoder::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSTextDecoder::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSTextDecoderConstructor::create(init.vm, init.global, WebCore::JSTextDecoderConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSTextDecoderPrototype*>(init.prototype))); + }); m_JSRequest.initLater( - [](LazyClassStructure::Initializer& init) { - init.setPrototype(WebCore::JSRequest::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); - init.setStructure(WebCore::JSRequest::createStructure(init.vm, init.global, init.prototype)); - init.setConstructor(WebCore::JSRequestConstructor::create(init.vm, init.global, WebCore::JSRequestConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSRequestPrototype*>(init.prototype))); - }); + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSRequest::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSRequest::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSRequestConstructor::create(init.vm, init.global, WebCore::JSRequestConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSRequestPrototype*>(init.prototype))); + }); m_JSResponse.initLater( - [](LazyClassStructure::Initializer& init) { - init.setPrototype(WebCore::JSResponse::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); - init.setStructure(WebCore::JSResponse::createStructure(init.vm, init.global, init.prototype)); - init.setConstructor(WebCore::JSResponseConstructor::create(init.vm, init.global, WebCore::JSResponseConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSResponsePrototype*>(init.prototype))); - }); + [](LazyClassStructure::Initializer& init) { + init.setPrototype(WebCore::JSResponse::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global))); + init.setStructure(WebCore::JSResponse::createStructure(init.vm, init.global, init.prototype)); + init.setConstructor(WebCore::JSResponseConstructor::create(init.vm, init.global, WebCore::JSResponseConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSResponsePrototype*>(init.prototype))); + }); } template<typename Visitor> -void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& visitor) +void GlobalObject::visitGeneratedLazyClasses(GlobalObject* thisObject, Visitor& visitor) { - thisObject->m_JSSHA1.visit(visitor); - thisObject->m_JSMD5.visit(visitor); - thisObject->m_JSMD4.visit(visitor); - thisObject->m_JSSHA224.visit(visitor); - thisObject->m_JSSHA512.visit(visitor); - thisObject->m_JSSHA384.visit(visitor); - thisObject->m_JSSHA256.visit(visitor); - thisObject->m_JSSHA512_256.visit(visitor); - thisObject->m_JSTextDecoder.visit(visitor); - thisObject->m_JSRequest.visit(visitor); - thisObject->m_JSResponse.visit(visitor); + thisObject->m_JSSHA1.visit(visitor); + visitor.append(thisObject->m_JSSHA1SetterValue); + thisObject->m_JSMD5.visit(visitor); + visitor.append(thisObject->m_JSMD5SetterValue); + thisObject->m_JSMD4.visit(visitor); + visitor.append(thisObject->m_JSMD4SetterValue); + thisObject->m_JSSHA224.visit(visitor); + visitor.append(thisObject->m_JSSHA224SetterValue); + thisObject->m_JSSHA512.visit(visitor); + visitor.append(thisObject->m_JSSHA512SetterValue); + thisObject->m_JSSHA384.visit(visitor); + visitor.append(thisObject->m_JSSHA384SetterValue); + thisObject->m_JSSHA256.visit(visitor); + visitor.append(thisObject->m_JSSHA256SetterValue); + thisObject->m_JSSHA512_256.visit(visitor); + visitor.append(thisObject->m_JSSHA512_256SetterValue); + thisObject->m_JSTextDecoder.visit(visitor); + visitor.append(thisObject->m_JSTextDecoderSetterValue); + thisObject->m_JSRequest.visit(visitor); + visitor.append(thisObject->m_JSRequestSetterValue); + thisObject->m_JSResponse.visit(visitor); + visitor.append(thisObject->m_JSResponseSetterValue); }
\ No newline at end of file diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 54fa5bad7..5ad12624a 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -277,6 +277,31 @@ extern "C" bool Zig__GlobalObject__resetModuleRegistryMap(JSC__JSGlobalObject* g extern "C" void Bun__reportError(JSC__JSGlobalObject*, JSC__JSValue); +#define GENERATED_CONSTRUCTOR_GETTER(ConstructorName) \ + JSC_DECLARE_CUSTOM_GETTER(ConstructorName##_getter); \ + JSC_DEFINE_CUSTOM_GETTER(ConstructorName##_getter, \ + (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, \ + JSC::PropertyName)) \ + { \ + Zig::GlobalObject* thisObject = JSC::jsCast<Zig::GlobalObject*>(lexicalGlobalObject); \ + if (JSValue override = thisObject->m_##ConstructorName##SetterValue.get()) { \ + return JSC::JSValue::encode(override); \ + } \ + return JSC::JSValue::encode( \ + thisObject->ConstructorName##Constructor()); \ + } + +#define GENERATED_CONSTRUCTOR_SETTER(ConstructorName) \ + JSC_DECLARE_CUSTOM_SETTER(ConstructorName##_setter); \ + JSC_DEFINE_CUSTOM_SETTER(ConstructorName##_setter, \ + (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, \ + EncodedJSValue value, JSC::PropertyName)) \ + { \ + Zig::GlobalObject* thisObject = JSC::jsCast<Zig::GlobalObject*>(lexicalGlobalObject); \ + thisObject->m_##ConstructorName##SetterValue.set(thisObject->vm(), thisObject, JSValue::decode(value)); \ + return true; \ + } + namespace Zig { using namespace WebCore; @@ -477,28 +502,6 @@ JSC_DEFINE_CUSTOM_GETTER(JSURLSearchParams_getter, WebCore::JSURLSearchParams::getConstructor(JSC::getVM(lexicalGlobalObject), thisObject)); } -JSC_DECLARE_CUSTOM_GETTER(JSRequest_getter); - -JSC_DEFINE_CUSTOM_GETTER(JSRequest_getter, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::PropertyName)) -{ - Zig::GlobalObject* thisObject = JSC::jsCast<Zig::GlobalObject*>(lexicalGlobalObject); - return JSC::JSValue::encode( - thisObject->JSRequestConstructor()); -} - -JSC_DECLARE_CUSTOM_GETTER(JSResponse_getter); - -JSC_DEFINE_CUSTOM_GETTER(JSResponse_getter, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::PropertyName)) -{ - Zig::GlobalObject* thisObject = JSC::jsCast<Zig::GlobalObject*>(lexicalGlobalObject); - return JSC::JSValue::encode( - thisObject->JSResponseConstructor()); -} - JSC_DECLARE_CUSTOM_GETTER(JSErrorEvent_getter); JSC_DEFINE_CUSTOM_GETTER(JSErrorEvent_getter, @@ -521,16 +524,14 @@ JSC_DEFINE_CUSTOM_GETTER(JSCloseEvent_getter, WebCore::JSCloseEvent::getConstructor(JSC::getVM(lexicalGlobalObject), thisObject)); } -JSC_DECLARE_CUSTOM_GETTER(JSTextDecoder_getter); +GENERATED_CONSTRUCTOR_GETTER(JSTextDecoder); +GENERATED_CONSTRUCTOR_SETTER(JSTextDecoder); -JSC_DEFINE_CUSTOM_GETTER(JSTextDecoder_getter, - (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, - JSC::PropertyName)) -{ - Zig::GlobalObject* thisObject = JSC::jsCast<Zig::GlobalObject*>(lexicalGlobalObject); - return JSC::JSValue::encode( - thisObject->JSTextDecoderConstructor()); -} +GENERATED_CONSTRUCTOR_GETTER(JSResponse); +GENERATED_CONSTRUCTOR_SETTER(JSResponse); + +GENERATED_CONSTRUCTOR_GETTER(JSRequest); +GENERATED_CONSTRUCTOR_SETTER(JSRequest); JSC_DECLARE_CUSTOM_GETTER(JSMessageEvent_getter); @@ -2139,14 +2140,14 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "URLSearchParams"_s), JSC::CustomGetterSetter::create(vm, JSURLSearchParams_getter, nullptr), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); - putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "Request"_s), JSC::CustomGetterSetter::create(vm, JSRequest_getter, nullptr), - JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); + putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "Request"_s), JSC::CustomGetterSetter::create(vm, JSRequest_getter, JSRequest_setter), + JSC::PropertyAttribute::DontDelete | 0); - putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "Response"_s), JSC::CustomGetterSetter::create(vm, JSResponse_getter, nullptr), - JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); + putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "Response"_s), JSC::CustomGetterSetter::create(vm, JSResponse_getter, JSResponse_setter), + JSC::PropertyAttribute::DontDelete | 0); - putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "TextDecoder"_s), JSC::CustomGetterSetter::create(vm, JSTextDecoder_getter, nullptr), - JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); + putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "TextDecoder"_s), JSC::CustomGetterSetter::create(vm, JSTextDecoder_getter, JSTextDecoder_setter), + JSC::PropertyAttribute::DontDelete | 0); putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "DOMException"_s), JSC::CustomGetterSetter::create(vm, JSDOMException_getter, nullptr), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); diff --git a/src/bun.js/scripts/generate-classes.ts b/src/bun.js/scripts/generate-classes.ts index eb93e6cd2..c3dc22a9f 100644 --- a/src/bun.js/scripts/generate-classes.ts +++ b/src/bun.js/scripts/generate-classes.ts @@ -1086,7 +1086,9 @@ function generateLazyClassStructureHeader( JSC::JSValue ${className(typeName)}Prototype() { return m_${className( typeName )}.prototypeInitializedOnMainThread(this); } - JSC::LazyClassStructure m_${className(typeName)}; + JSC::LazyClassStructure m_${className(typeName)}; + bool has${className(typeName)}SetterValue { false }; + mutable JSC::WriteBarrier<JSC::Unknown> m_${className(typeName)}SetterValue; `.trim(); } @@ -1187,7 +1189,11 @@ template<typename Visitor> void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& visitor) { ${classes - .map((a) => `thisObject->m_${className(a.name)}.visit(visitor);`) + .map( + (a) => + `thisObject->m_${className(a.name)}.visit(visitor); +visitor.visit(thisObject->m_${className(a.name)}SetterValue);` + ) .join("\n ")} } diff --git a/test/bun.js/globals.test.js b/test/bun.js/globals.test.js index b498e0e8e..68547ee21 100644 --- a/test/bun.js/globals.test.js +++ b/test/bun.js/globals.test.js @@ -22,6 +22,25 @@ it("extendable", () => { expect(true).toBe(true); }); +it("writable", () => { + const classes = [ + // ["Blob", Blob], + ["TextDecoder", TextDecoder], + // ["TextEncoder", TextEncoder], + ["Request", Request], + ["Response", Response], + // ["Headers", Headers], + // ["HTMLRewriter", HTMLRewriter], + // ["Transpiler", Bun.Transpiler], + ]; + for (let [name, Class] of classes) { + globalThis[name] = 123; + expect(globalThis[name]).toBe(123); + globalThis[name] = Class; + expect(globalThis[name]).toBe(Class); + } +}); + it("name", () => { const classes = [ ["Blob", Blob], |