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 39d2410
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 41 deletions.
17 changes: 11 additions & 6 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ EventEmitter.init = function(opts) {

if (this._events === undefined ||
this._events === ObjectGetPrototypeOf(this)._events) {
this._events = { __proto__: null };
this._reset();
this._eventsCount = 0;
}

Expand All @@ -359,6 +359,10 @@ EventEmitter.init = function(opts) {
}
};

EventEmitter.prototype._reset = function () {

Check failure on line 362 in lib/events.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Unexpected space before function parentheses
this._events = { __proto__: null };
}

Check failure on line 364 in lib/events.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon

function addCatch(that, promise, type, args) {
if (!that[kCapture]) {
return;
Expand Down Expand Up @@ -549,7 +553,8 @@ function _addListener(target, type, listener, prepend) {

events = target._events;
if (events === undefined) {
events = target._events = { __proto__: null };
target._reset();
events = target._events;
target._eventsCount = 0;
} else {
// To avoid recursion in the case that type === "newListener"! Before
Expand Down Expand Up @@ -687,7 +692,7 @@ EventEmitter.prototype.removeListener =

if (list === listener || list.listener === listener) {
if (--this._eventsCount === 0)
this._events = { __proto__: null };
this._reset();
else {
delete events[type];
if (events.removeListener)
Expand Down Expand Up @@ -742,11 +747,11 @@ EventEmitter.prototype.removeAllListeners =
// Not listening for removeListener, no need to emit
if (events.removeListener === undefined) {
if (arguments.length === 0) {
this._events = { __proto__: null };
this._reset();
this._eventsCount = 0;
} else if (events[type] !== undefined) {
if (--this._eventsCount === 0)
this._events = { __proto__: null };
this._reset();
else
delete events[type];
}
Expand All @@ -760,7 +765,7 @@ EventEmitter.prototype.removeAllListeners =
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = { __proto__: null };
this._reset();
this._eventsCount = 0;
return this;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/streams/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ function destroyer(stream, err) {
}

module.exports = {
kConstruct,
kDestroy,
construct,
destroyer,
destroy,
Expand Down
34 changes: 19 additions & 15 deletions lib/internal/streams/duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,6 @@ function Duplex(options) {
if (!(this instanceof Duplex))
return new Duplex(options);

this._events = {
close: undefined,
error: undefined,
prefinish: undefined,
finish: undefined,
drain: undefined,
data: undefined,
end: undefined,
pause: undefined,
resume: undefined,
readable: undefined,
pipe: undefined,
unpipe: undefined,
};

this._readableState = new Readable.ReadableState(options, this, true);
this._writableState = new Writable.WritableState(options, this, true);

Expand Down Expand Up @@ -131,6 +116,25 @@ function Duplex(options) {
}
}

Duplex.prototype._reset = function () {

Check failure on line 119 in lib/internal/streams/duplex.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Unexpected space before function parentheses
this._events = {
close: undefined,
error: undefined,
prefinish: undefined,
finish: undefined,
drain: undefined,
data: undefined,
end: undefined,
pause: undefined,
resume: undefined,
readable: undefined,
pipe: undefined,
unpipe: undefined,
[destroyImpl.kConstruct]: undefined,
[destroyImpl.kDestroy]: undefined,
};
};

ObjectDefineProperties(Duplex.prototype, {
writable:
{ __proto__: null, ...ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writable') },
Expand Down
28 changes: 16 additions & 12 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,6 @@ function Readable(options) {
if (!(this instanceof Readable))
return new Readable(options);

this._events = {
close: undefined,
error: undefined,
data: undefined,
end: undefined,
pause: undefined,
resume: undefined,
readable: undefined,
pipe: undefined,
unpipe: undefined,
};

this._readableState = new ReadableState(options, this, false);

if (options) {
Expand All @@ -353,6 +341,22 @@ function Readable(options) {
}
}

Readable.prototype._reset = function () {

Check failure on line 344 in lib/internal/streams/readable.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Unexpected space before function parentheses
this._events = {
close: undefined,
error: undefined,
data: undefined,
end: undefined,
pause: undefined,
resume: undefined,
readable: undefined,
pipe: undefined,
unpipe: undefined,
[destroyImpl.kConstruct]: undefined,
[destroyImpl.kDestroy]: undefined,
};
};

Readable.prototype.destroy = destroyImpl.destroy;
Readable.prototype._undestroy = destroyImpl.undestroy;
Readable.prototype._destroy = function(err, cb) {
Expand Down
20 changes: 12 additions & 8 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,6 @@ function Writable(options) {
if (!(this instanceof Writable))
return new Writable(options);

this._events = {
close: undefined,
error: undefined,
prefinish: undefined,
finish: undefined,
drain: undefined,
};

this._writableState = new WritableState(options, this, false);

if (options) {
Expand Down Expand Up @@ -431,6 +423,18 @@ ObjectDefineProperty(Writable, SymbolHasInstance, {
},
});

Writable.prototype._reset = function () {

Check failure on line 426 in lib/internal/streams/writable.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Unexpected space before function parentheses
this._events = {
close: undefined,
error: undefined,
prefinish: undefined,
finish: undefined,
drain: undefined,
[destroyImpl.kConstruct]: undefined,
[destroyImpl.kDestroy]: undefined,
};
};

// Otherwise people can pipe Writable streams, which is just wrong.
Writable.prototype.pipe = function() {
errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
Expand Down

0 comments on commit 39d2410

Please sign in to comment.