From 89ad099606765945b6740c8baf5fb9c4de595ecf Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 27 Oct 2023 18:11:25 +0200 Subject: [PATCH] fixuP --- lib/events.js | 14 ++++++++++++-- lib/internal/streams/duplex.js | 2 ++ lib/internal/streams/readable.js | 2 ++ lib/internal/streams/writable.js | 2 ++ test/parallel/test-readline-promises-interface.js | 2 +- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/events.js b/lib/events.js index a1837cc1a9107e..3ba2484ece938f 100644 --- a/lib/events.js +++ b/lib/events.js @@ -87,6 +87,7 @@ const { const kCapture = Symbol('kCapture'); const kErrorMonitor = Symbol('events.errorMonitor'); +const kShapeMode = Symbol('shapeMode'); const kMaxEventTargetListeners = Symbol('events.maxEventTargetListeners'); const kMaxEventTargetListenersWarned = Symbol('events.maxEventTargetListenersWarned'); @@ -344,6 +345,9 @@ EventEmitter.init = function(opts) { this._events === ObjectGetPrototypeOf(this)._events) { this._events = { __proto__: null }; this._eventsCount = 0; + this[kShapeMode] = false; + } else { + this[kShapeMode] = true; } this._maxListeners = this._maxListeners || undefined; @@ -686,9 +690,13 @@ EventEmitter.prototype.removeListener = return this; if (list === listener || list.listener === listener) { - if (--this._eventsCount === 0) + this._eventsCount -= 1; + + if (this[kShapeMode]) { + events[type] = undefined; + } else if (this._eventsCount === 0) { this._events = { __proto__: null }; - else { + } else { delete events[type]; if (events.removeListener) this.emit('removeListener', type, list.listener || listener); @@ -750,6 +758,7 @@ EventEmitter.prototype.removeAllListeners = else delete events[type]; } + this[kShapeMode] = false; return this; } @@ -762,6 +771,7 @@ EventEmitter.prototype.removeAllListeners = this.removeAllListeners('removeListener'); this._events = { __proto__: null }; this._eventsCount = 0; + this[kShapeMode] = false; return this; } diff --git a/lib/internal/streams/duplex.js b/lib/internal/streams/duplex.js index 2b3fe64df9e03a..153c39a4036d6f 100644 --- a/lib/internal/streams/duplex.js +++ b/lib/internal/streams/duplex.js @@ -76,6 +76,8 @@ function Duplex(options) { readable: undefined, pipe: undefined, unpipe: undefined, + [destroyImpl.kConstruct]: undefined, + [destroyImpl.kDestroy]: undefined, }; this._readableState = new Readable.ReadableState(options, this, true); diff --git a/lib/internal/streams/readable.js b/lib/internal/streams/readable.js index 83f09194a6358d..6ca529b60f6678 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -326,6 +326,8 @@ function Readable(options) { readable: undefined, pipe: undefined, unpipe: undefined, + [destroyImpl.kConstruct]: undefined, + [destroyImpl.kDestroy]: undefined, }; this._readableState = new ReadableState(options, this, false); diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index e2a26f36b582c1..17dfadeb275028 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -388,6 +388,8 @@ function Writable(options) { prefinish: undefined, finish: undefined, drain: undefined, + [destroyImpl.kConstruct]: undefined, + [destroyImpl.kDestroy]: undefined, }; this._writableState = new WritableState(options, this, false); diff --git a/test/parallel/test-readline-promises-interface.js b/test/parallel/test-readline-promises-interface.js index 2a8c5aae4e3949..ce5526623237de 100644 --- a/test/parallel/test-readline-promises-interface.js +++ b/test/parallel/test-readline-promises-interface.js @@ -20,7 +20,7 @@ class FakeInput extends EventEmitter { } function isWarned(emitter) { - for (const name in emitter) { + for (const name of Object.keys(emitter)) { const listeners = emitter[name]; if (listeners.warned) return true; }