1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 00:21:05 -05:00

fix(std/node) Fix event extendability (#8409)

This commit is contained in:
Steven Guerrero 2020-11-17 19:49:57 -05:00 committed by GitHub
parent f7afe2b78f
commit b6fa6d6aac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -231,7 +231,7 @@ export default class EventEmitter {
eventName: string | symbol,
listener: GenericFunction | WrappedFunction,
): this {
return this.addListener(eventName, listener);
return this._addListener(eventName, listener, false);
}
/**

View file

@ -667,3 +667,21 @@ Deno.test({
assertEquals(ee.listenerCount("error"), 0);
},
});
// Event emitter's `on` previously referenced addListener internally, so overriding addListener
// would cause a deadlock
// This is a regression test
Deno.test("Elements that extend EventEmitter listener alias don't end up in a deadlock", () => {
class X extends EventEmitter {
addListener(eventName: string, listener: () => void) {
return super.on(eventName, listener);
}
}
const x = new X();
try {
x.on("x", () => {});
} catch (e) {
fail();
}
});