diff options
author | 2022-08-21 20:34:31 +0800 | |
---|---|---|
committer | 2022-08-21 05:34:31 -0700 | |
commit | 3d8bc140aad4d7b035836037e94d688a11f0d7fb (patch) | |
tree | bf97478c8fb77af3e96088425fc59fd769e60365 /src/bun.js/modules/EventsModule.h | |
parent | d8f40e080da54ce2cd91eb40898cb86ef22a58a5 (diff) | |
download | bun-3d8bc140aad4d7b035836037e94d688a11f0d7fb.tar.gz bun-3d8bc140aad4d7b035836037e94d688a11f0d7fb.tar.zst bun-3d8bc140aad4d7b035836037e94d688a11f0d7fb.zip |
Add native EventEmitter (#1123)
* Add native EventEmitter
* add listeners, listenerCount and eventNames
* add global functions
* add Object to EventEmitter conversion
* fix upon review
Diffstat (limited to 'src/bun.js/modules/EventsModule.h')
-rw-r--r-- | src/bun.js/modules/EventsModule.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/bun.js/modules/EventsModule.h b/src/bun.js/modules/EventsModule.h new file mode 100644 index 000000000..5adb19d01 --- /dev/null +++ b/src/bun.js/modules/EventsModule.h @@ -0,0 +1,27 @@ +#include "../bindings/ZigGlobalObject.h" +#include "JavaScriptCore/JSGlobalObject.h" + +namespace Zig { + +inline void generateEventsSourceCode(JSC::JSGlobalObject* lexicalGlobalObject, JSC::Identifier moduleKey, Vector<JSC::Identifier, 4>& exportNames, JSC::MarkedArgumentBuffer& exportValues) { + JSC::VM& vm = lexicalGlobalObject->vm(); + GlobalObject* globalObject = reinterpret_cast<GlobalObject*>(lexicalGlobalObject); + + exportNames.append(JSC::Identifier::fromString(vm, "EventEmitter"_s)); + exportValues.append(WebCore::JSEventEmitter::getConstructor(vm, globalObject)); + + exportNames.append(JSC::Identifier::fromString(vm, "getEventListeners"_s)); + exportValues.append(JSC::JSFunction::create(vm, lexicalGlobalObject, 0, + MAKE_STATIC_STRING_IMPL("getEventListeners"), Events_functionGetEventListeners, ImplementationVisibility::Public)); + exportNames.append(JSC::Identifier::fromString(vm, "listenerCount"_s)); + exportValues.append(JSC::JSFunction::create(vm, lexicalGlobalObject, 0, + MAKE_STATIC_STRING_IMPL("listenerCount"), Events_functionListenerCount, ImplementationVisibility::Public)); + exportNames.append(JSC::Identifier::fromString(vm, "once"_s)); + exportValues.append(JSC::JSFunction::create(vm, lexicalGlobalObject, 0, + MAKE_STATIC_STRING_IMPL("once"), Events_functionOnce, ImplementationVisibility::Public)); + exportNames.append(JSC::Identifier::fromString(vm, "on"_s)); + exportValues.append(JSC::JSFunction::create(vm, lexicalGlobalObject, 0, + MAKE_STATIC_STRING_IMPL("on"), Events_functionOn, ImplementationVisibility::Public)); +} + +} |