@@ -72,16 +72,7 @@ void JSModuleNamespaceObject::finishCreation(JSGlobalObject* globalObject, Abstr
7272 }
7373 }
7474
75- #if !USE(BUN_JSC_ADDITIONS)
7675 putDirect (vm, vm.propertyNames ->toStringTagSymbol , jsNontrivialString (vm, " Module" _s), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
77- #else
78- // Spec diversion:
79- // Allow modifying the toStringTag of module namespace objects in Bun.
80- // This is used when assigning a CommonJS exports object to a namespace object.
81- // Some code expects [object Object] over [object Module].
82- putDirect (vm, vm.propertyNames ->toStringTagSymbol , jsNontrivialString (vm, " Module" _s), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete);
83- #endif
84-
8576
8677#if USE(BUN_JSC_ADDITIONS)
8778 if (shouldPreventExtensions)
@@ -147,8 +138,15 @@ bool JSModuleNamespaceObject::getOwnPropertySlotCommon(JSGlobalObject* globalObj
147138 slot.setIsTaintedByOpaqueObject ();
148139
149140 auto iterator = m_exports.find (propertyName.uid ());
150- if (iterator == m_exports.end ())
141+ if (iterator == m_exports.end ()) {
142+ #if USE(BUN_JSC_ADDITIONS)
143+ if (propertyName == vm.propertyNames ->__esModule ) {
144+ return Base::getOwnPropertySlot (this , globalObject, propertyName, slot);
145+ }
146+ #endif
151147 return false ;
148+ }
149+
152150 ExportEntry& exportEntry = iterator->value ;
153151
154152 switch (slot.internalMethodType ()) {
@@ -205,7 +203,7 @@ bool JSModuleNamespaceObject::getOwnPropertySlotByIndex(JSObject* cell, JSGlobal
205203 return thisObject->getOwnPropertySlotCommon (globalObject, Identifier::from (vm, propertyName), slot);
206204}
207205
208- bool JSModuleNamespaceObject::put (JSCell* cell, JSGlobalObject* globalObject, PropertyName, JSValue, PutPropertySlot& slot)
206+ bool JSModuleNamespaceObject::put (JSCell* cell, JSGlobalObject* globalObject, PropertyName propertyName , JSValue value , PutPropertySlot& slot)
209207{
210208 VM& vm = globalObject->vm ();
211209 auto scope = DECLARE_THROW_SCOPE (vm);
@@ -214,6 +212,8 @@ bool JSModuleNamespaceObject::put(JSCell* cell, JSGlobalObject* globalObject, Pr
214212 auto * thisObject = jsCast<JSModuleNamespaceObject*>(cell);
215213 if (thisObject->m_isOverridingValue ) {
216214 return true ;
215+ } else if (UNLIKELY (propertyName == vm.propertyNames ->__esModule && !thisObject->m_exports .contains (propertyName.uid ()))) {
216+ RELEASE_AND_RETURN (scope, Base::put (thisObject, globalObject, propertyName, value, slot));
217217 }
218218#endif
219219
@@ -293,6 +293,8 @@ bool JSModuleNamespaceObject::defineOwnProperty(JSObject* cell, JSGlobalObject*
293293#if USE(BUN_JSC_ADDITIONS)
294294 if (thisObject->m_isOverridingValue ) {
295295 return true ;
296+ } else if (propertyName == vm.propertyNames ->__esModule && !thisObject->m_exports .contains (propertyName.uid ())) {
297+ RELEASE_AND_RETURN (scope, Base::defineOwnProperty (thisObject, globalObject, propertyName, descriptor, shouldThrow));
296298 }
297299#endif
298300
0 commit comments