Skip to content

Commit 39d2410

Browse files
committed
fixup
1 parent 321c41c commit 39d2410

File tree

5 files changed

+60
-41
lines changed

5 files changed

+60
-41
lines changed

lib/events.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ EventEmitter.init = function(opts) {
342342

343343
if (this._events === undefined ||
344344
this._events === ObjectGetPrototypeOf(this)._events) {
345-
this._events = { __proto__: null };
345+
this._reset();
346346
this._eventsCount = 0;
347347
}
348348

@@ -359,6 +359,10 @@ EventEmitter.init = function(opts) {
359359
}
360360
};
361361

362+
EventEmitter.prototype._reset = function () {
363+
this._events = { __proto__: null };
364+
}
365+
362366
function addCatch(that, promise, type, args) {
363367
if (!that[kCapture]) {
364368
return;
@@ -549,7 +553,8 @@ function _addListener(target, type, listener, prepend) {
549553

550554
events = target._events;
551555
if (events === undefined) {
552-
events = target._events = { __proto__: null };
556+
target._reset();
557+
events = target._events;
553558
target._eventsCount = 0;
554559
} else {
555560
// To avoid recursion in the case that type === "newListener"! Before
@@ -687,7 +692,7 @@ EventEmitter.prototype.removeListener =
687692

688693
if (list === listener || list.listener === listener) {
689694
if (--this._eventsCount === 0)
690-
this._events = { __proto__: null };
695+
this._reset();
691696
else {
692697
delete events[type];
693698
if (events.removeListener)
@@ -742,11 +747,11 @@ EventEmitter.prototype.removeAllListeners =
742747
// Not listening for removeListener, no need to emit
743748
if (events.removeListener === undefined) {
744749
if (arguments.length === 0) {
745-
this._events = { __proto__: null };
750+
this._reset();
746751
this._eventsCount = 0;
747752
} else if (events[type] !== undefined) {
748753
if (--this._eventsCount === 0)
749-
this._events = { __proto__: null };
754+
this._reset();
750755
else
751756
delete events[type];
752757
}
@@ -760,7 +765,7 @@ EventEmitter.prototype.removeAllListeners =
760765
this.removeAllListeners(key);
761766
}
762767
this.removeAllListeners('removeListener');
763-
this._events = { __proto__: null };
768+
this._reset();
764769
this._eventsCount = 0;
765770
return this;
766771
}

lib/internal/streams/destroy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ function destroyer(stream, err) {
332332
}
333333

334334
module.exports = {
335+
kConstruct,
336+
kDestroy,
335337
construct,
336338
destroyer,
337339
destroy,

lib/internal/streams/duplex.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,6 @@ function Duplex(options) {
6363
if (!(this instanceof Duplex))
6464
return new Duplex(options);
6565

66-
this._events = {
67-
close: undefined,
68-
error: undefined,
69-
prefinish: undefined,
70-
finish: undefined,
71-
drain: undefined,
72-
data: undefined,
73-
end: undefined,
74-
pause: undefined,
75-
resume: undefined,
76-
readable: undefined,
77-
pipe: undefined,
78-
unpipe: undefined,
79-
};
80-
8166
this._readableState = new Readable.ReadableState(options, this, true);
8267
this._writableState = new Writable.WritableState(options, this, true);
8368

@@ -131,6 +116,25 @@ function Duplex(options) {
131116
}
132117
}
133118

119+
Duplex.prototype._reset = function () {
120+
this._events = {
121+
close: undefined,
122+
error: undefined,
123+
prefinish: undefined,
124+
finish: undefined,
125+
drain: undefined,
126+
data: undefined,
127+
end: undefined,
128+
pause: undefined,
129+
resume: undefined,
130+
readable: undefined,
131+
pipe: undefined,
132+
unpipe: undefined,
133+
[destroyImpl.kConstruct]: undefined,
134+
[destroyImpl.kDestroy]: undefined,
135+
};
136+
};
137+
134138
ObjectDefineProperties(Duplex.prototype, {
135139
writable:
136140
{ __proto__: null, ...ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writable') },

lib/internal/streams/readable.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,6 @@ function Readable(options) {
316316
if (!(this instanceof Readable))
317317
return new Readable(options);
318318

319-
this._events = {
320-
close: undefined,
321-
error: undefined,
322-
data: undefined,
323-
end: undefined,
324-
pause: undefined,
325-
resume: undefined,
326-
readable: undefined,
327-
pipe: undefined,
328-
unpipe: undefined,
329-
};
330-
331319
this._readableState = new ReadableState(options, this, false);
332320

333321
if (options) {
@@ -353,6 +341,22 @@ function Readable(options) {
353341
}
354342
}
355343

344+
Readable.prototype._reset = function () {
345+
this._events = {
346+
close: undefined,
347+
error: undefined,
348+
data: undefined,
349+
end: undefined,
350+
pause: undefined,
351+
resume: undefined,
352+
readable: undefined,
353+
pipe: undefined,
354+
unpipe: undefined,
355+
[destroyImpl.kConstruct]: undefined,
356+
[destroyImpl.kDestroy]: undefined,
357+
};
358+
};
359+
356360
Readable.prototype.destroy = destroyImpl.destroy;
357361
Readable.prototype._undestroy = destroyImpl.undestroy;
358362
Readable.prototype._destroy = function(err, cb) {

lib/internal/streams/writable.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,6 @@ function Writable(options) {
382382
if (!(this instanceof Writable))
383383
return new Writable(options);
384384

385-
this._events = {
386-
close: undefined,
387-
error: undefined,
388-
prefinish: undefined,
389-
finish: undefined,
390-
drain: undefined,
391-
};
392-
393385
this._writableState = new WritableState(options, this, false);
394386

395387
if (options) {
@@ -431,6 +423,18 @@ ObjectDefineProperty(Writable, SymbolHasInstance, {
431423
},
432424
});
433425

426+
Writable.prototype._reset = function () {
427+
this._events = {
428+
close: undefined,
429+
error: undefined,
430+
prefinish: undefined,
431+
finish: undefined,
432+
drain: undefined,
433+
[destroyImpl.kConstruct]: undefined,
434+
[destroyImpl.kDestroy]: undefined,
435+
};
436+
};
437+
434438
// Otherwise people can pipe Writable streams, which is just wrong.
435439
Writable.prototype.pipe = function() {
436440
errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());

0 commit comments

Comments
 (0)