aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/modules/EventsModule.h
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-28 14:37:35 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-28 14:37:35 -0700
commitb74351e55fcb54451e793879302754de440e3da0 (patch)
tree6070b9c33c17767f49d931393b9c3000e12d406b /src/bun.js/modules/EventsModule.h
parenta1b4dc42cb863eedbbe6735cb29a3d6941e02e04 (diff)
downloadbun-b74351e55fcb54451e793879302754de440e3da0.tar.gz
bun-b74351e55fcb54451e793879302754de440e3da0.tar.zst
bun-b74351e55fcb54451e793879302754de440e3da0.zip
Support a `default` object in CommonJS wrapper
Fixes https://github.com/oven-sh/bun/issues/1284 Related to https://github.com/oven-sh/bun/issues/1285
Diffstat (limited to 'src/bun.js/modules/EventsModule.h')
-rw-r--r--src/bun.js/modules/EventsModule.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/bun.js/modules/EventsModule.h b/src/bun.js/modules/EventsModule.h
index d1e14a2db..00966b858 100644
--- a/src/bun.js/modules/EventsModule.h
+++ b/src/bun.js/modules/EventsModule.h
@@ -3,6 +3,7 @@
namespace Zig {
using namespace WebCore;
+
inline void generateEventsSourceCode(JSC::JSGlobalObject *lexicalGlobalObject,
JSC::Identifier moduleKey,
Vector<JSC::Identifier, 4> &exportNames,
@@ -31,6 +32,23 @@ inline void generateEventsSourceCode(JSC::JSGlobalObject *lexicalGlobalObject,
exportValues.append(JSC::JSFunction::create(
vm, lexicalGlobalObject, 0, MAKE_STATIC_STRING_IMPL("on"),
Events_functionOn, ImplementationVisibility::Public));
+
+ JSFunction *eventEmitterModuleCJS =
+ jsCast<JSFunction *>(WebCore::JSEventEmitter::getConstructor(
+ vm, reinterpret_cast<Zig::GlobalObject *>(globalObject)));
+
+ eventEmitterModuleCJS->putDirect(
+ vm,
+ PropertyName(
+ Identifier::fromUid(vm.symbolRegistry().symbolForKey("CommonJS"_s))),
+ jsNumber(0), 0);
+
+ for (size_t i = 0; i < exportNames.size(); i++) {
+ eventEmitterModuleCJS->putDirect(vm, exportNames[i], exportValues.at(i), 0);
+ }
+
+ exportNames.append(JSC::Identifier::fromString(vm, "default"_s));
+ exportValues.append(eventEmitterModuleCJS);
}
} // namespace Zig