Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions lib/internal/streams/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,7 @@ Stream.prototype.eventNames = function eventNames() {
};

function prependListener(emitter, event, fn) {
// Sadly this is not cacheable as some libraries bundle their own
// event emitter implementation with them.
if (typeof emitter.prependListener === 'function')
return emitter.prependListener(event, fn);

// This is a hack to make sure that our error handler is attached before any
// userland ones. NEVER DO THIS. This is here only because this code needs
// to continue to work with older versions of Node.js that do not include
// the prependListener() method. The goal is to eventually remove this hack.
if (!emitter._events || !emitter._events[event])
emitter.on(event, fn);
else if (ArrayIsArray(emitter._events[event]))
emitter._events[event].unshift(fn);
else
emitter._events[event] = [fn, emitter._events[event]];
emitter.prependListener(event, fn);
}

module.exports = { Stream, prependListener };
23 changes: 0 additions & 23 deletions test/parallel/test-event-emitter-prepend.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,3 @@ myEE.prependOnceListener('foo',
common.mustCall(() => assert.strictEqual(m++, 0)));

myEE.emit('foo');

// Test fallback if prependListener is undefined.
const stream = require('stream');

delete EventEmitter.prototype.prependListener;

function Writable() {
this.writable = true;
stream.Stream.call(this);
}
Object.setPrototypeOf(Writable.prototype, stream.Stream.prototype);
Object.setPrototypeOf(Writable, stream.Stream);

function Readable() {
this.readable = true;
stream.Stream.call(this);
}
Object.setPrototypeOf(Readable.prototype, stream.Stream.prototype);
Object.setPrototypeOf(Readable, stream.Stream);

const w = new Writable();
const r = new Readable();
r.pipe(w);
7 changes: 2 additions & 5 deletions test/parallel/test-stream-events-prepend.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
const common = require('../common');
const stream = require('stream');

class Writable extends stream.Writable {
constructor() {
super();
this.prependListener = undefined;
}
// Test that pipe() correctly uses prependListener for error handlers.

class Writable extends stream.Writable {
_write(chunk, end, cb) {
cb();
}
Expand Down
Loading