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:
parent
f7afe2b78f
commit
b6fa6d6aac
2 changed files with 19 additions and 1 deletions
|
@ -231,7 +231,7 @@ export default class EventEmitter {
|
||||||
eventName: string | symbol,
|
eventName: string | symbol,
|
||||||
listener: GenericFunction | WrappedFunction,
|
listener: GenericFunction | WrappedFunction,
|
||||||
): this {
|
): this {
|
||||||
return this.addListener(eventName, listener);
|
return this._addListener(eventName, listener, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -667,3 +667,21 @@ Deno.test({
|
||||||
assertEquals(ee.listenerCount("error"), 0);
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue