[node:event] Add captureRejectionSymbol

This commit is contained in:
Jarred Sumner
2022-12-02 09:05:11 -08:00
parent b8586b33da
commit 2c0fd28e72
2 changed files with 13 additions and 2 deletions

View File

@@ -32,6 +32,10 @@ inline void generateEventsSourceCode(JSC::JSGlobalObject *lexicalGlobalObject,
exportValues.append(JSC::JSFunction::create(
vm, lexicalGlobalObject, 0, MAKE_STATIC_STRING_IMPL("on"),
Events_functionOn, ImplementationVisibility::Public));
exportNames.append(
JSC::Identifier::fromString(vm, "captureRejectionSymbol"_s));
exportValues.append(Symbol::create(
vm, vm.symbolRegistry().symbolForKey("nodejs.rejection"_s)));
JSFunction *eventEmitterModuleCJS =
jsCast<JSFunction *>(WebCore::JSEventEmitter::getConstructor(

View File

@@ -1,11 +1,18 @@
import { test, describe, expect } from "bun:test";
import { test, describe, expect, it } from "bun:test";
import fs from "node:fs";
// this is also testing that imports with default and named imports in the same statement work
// our transpiler transform changes this to a var with import.meta.require
import EventEmitter, { getEventListeners } from "node:events";
import EventEmitter, {
getEventListeners,
captureRejectionSymbol,
} from "node:events";
describe("EventEmitter", () => {
it("captureRejectionSymbol", () => {
expect(EventEmitter.captureRejectionSymbol).toBeDefined();
expect(captureRejectionSymbol).toBeDefined();
});
test("getEventListeners", () => {
expect(getEventListeners(new EventEmitter(), "hey").length).toBe(0);
});