diff --git a/lib/events.js b/lib/events.js index 62ed2191720125..4b16f9fa3c52a5 100644 --- a/lib/events.js +++ b/lib/events.js @@ -31,7 +31,6 @@ const { ObjectDefineProperty, ObjectGetPrototypeOf, ObjectSetPrototypeOf, - ObjectKeys, Promise, PromiseReject, PromiseResolve, @@ -521,7 +520,7 @@ EventEmitter.prototype.removeAllListeners = // Emit removeListener for all listeners on all events if (arguments.length === 0) { - for (const key of ObjectKeys(events)) { + for (const key of ReflectOwnKeys(events)) { if (key === 'removeListener') continue; this.removeAllListeners(key); } diff --git a/test/parallel/test-event-emitter-remove-all-listeners.js b/test/parallel/test-event-emitter-remove-all-listeners.js index 3dfe65a8b4bfd0..c62183fd08c203 100644 --- a/test/parallel/test-event-emitter-remove-all-listeners.js +++ b/test/parallel/test-event-emitter-remove-all-listeners.js @@ -108,3 +108,16 @@ function expect(expected) { ee._events = undefined; assert.strictEqual(ee, ee.removeAllListeners()); } + +{ + const ee = new events.EventEmitter(); + const symbol = Symbol('symbol'); + const noop = common.mustNotCall(); + ee.on(symbol, noop); + + ee.on('removeListener', common.mustCall((...args) => { + assert.deepStrictEqual(args, [symbol, noop]); + })); + + ee.removeAllListeners(); +}