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 4e46fdf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
15 changes: 13 additions & 2 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,

Check failure on line 40 in lib/events.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'ObjectKeys' is assigned a value but never used
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,9 +691,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);
Expand Down Expand Up @@ -750,6 +759,7 @@ EventEmitter.prototype.removeAllListeners =
else
delete events[type];
}
this[kShapeMode] = false;
return this;
}

Expand All @@ -762,6 +772,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 4e46fdf

Please sign in to comment.