diff options
author | 2023-06-15 01:18:23 -0700 | |
---|---|---|
committer | 2023-06-15 01:18:23 -0700 | |
commit | dc06caccaa6bd8fd273e16cff2c2e0c10f32c58e (patch) | |
tree | ee62eff2b60d567a337d3442ed703cf6f547bd76 /src/bun.js/bindings/ZigGlobalObject.cpp | |
parent | e6d4b3a89ac6631f54276a21d82d41f91fd41c76 (diff) | |
download | bun-dc06caccaa6bd8fd273e16cff2c2e0c10f32c58e.tar.gz bun-dc06caccaa6bd8fd273e16cff2c2e0c10f32c58e.tar.zst bun-dc06caccaa6bd8fd273e16cff2c2e0c10f32c58e.zip |
Tweak CommonJS output (#3320)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/bindings/ZigGlobalObject.cpp')
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index a2849939e..299ad7a8c 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -3168,6 +3168,15 @@ extern "C" void Bun__setOnEachMicrotaskTick(JSC::VM* vm, void* ptr, void (*callb }); } +JSC_DEFINE_CUSTOM_GETTER(BunCommonJSModule_getter, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName)) +{ + Zig::GlobalObject* bunGlobalObject = jsCast<Zig::GlobalObject*>(globalObject); + JSValue returnValue = bunGlobalObject->m_BunCommonJSModuleValue.get(); + if (!returnValue) { + returnValue = jsUndefined(); + } + return JSValue::encode(returnValue); +} // This implementation works the same as setTimeout(myFunction, 0) // TODO: make it more efficient // https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate @@ -3526,6 +3535,9 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "CloseEvent"_s), JSC::CustomGetterSetter::create(vm, JSCloseEvent_getter, nullptr), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); + putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "$_BunCommonJSModule_$"_s), JSC::CustomGetterSetter::create(vm, BunCommonJSModule_getter, nullptr), + JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); + auto bufferAccessor = JSC::CustomGetterSetter::create(vm, JSBuffer_getter, JSBuffer_setter); auto realBufferAccessor = JSC::CustomGetterSetter::create(vm, JSBuffer_privateGetter, nullptr); @@ -3935,6 +3947,7 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor) } thisObject->visitGeneratedLazyClasses<Visitor>(thisObject, visitor); + visitor.append(thisObject->m_BunCommonJSModuleValue); ScriptExecutionContext* context = thisObject->scriptExecutionContext(); visitor.addOpaqueRoot(context); |