Skip to content

Commit

Permalink
fixuP
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Oct 27, 2023
1 parent 321c41c commit 54755f2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const {
ObjectDefineProperty,
ObjectDefineProperties,
ObjectGetPrototypeOf,
ObjectKeys,
ObjectSetPrototypeOf,
Promise,
PromiseReject,
Expand Down Expand Up @@ -87,6 +88,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');
Expand Down Expand Up @@ -344,6 +346,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;
Expand Down Expand Up @@ -686,10 +691,18 @@ EventEmitter.prototype.removeListener =
return this;

if (list === listener || list.listener === listener) {
if (--this._eventsCount === 0)
this._events = { __proto__: null };
else {
delete events[type];
if (--this._eventsCount === 0) {
if (this[kShapeMode]) {
events[type] = undefined;
} else {
this._events = { __proto__: null };
}
} else {
if (this[kShapeMode]) {
events[type] = undefined;
} else {
delete events[type];
}
if (events.removeListener)
this.emit('removeListener', type, list.listener || listener);
}
Expand Down Expand Up @@ -750,6 +763,7 @@ EventEmitter.prototype.removeAllListeners =
else
delete events[type];
}
this[kShapeMode] = false;
return this;
}

Expand All @@ -762,6 +776,7 @@ EventEmitter.prototype.removeAllListeners =
this.removeAllListeners('removeListener');
this._events = { __proto__: null };
this._eventsCount = 0;
this[kShapeMode] = false;
return this;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/internal/streams/duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 54755f2

Please sign in to comment.