Skip to content

Commit

Permalink
fix prepend
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Aug 8, 2016
1 parent e8ee016 commit 25ec4c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
15 changes: 15 additions & 0 deletions build/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ const headRegexp = /(^module.exports = \w+;?)/m
/require\('internal\/streams\/BufferList'\)/,
'require(\'./internal/streams/BufferList\')'
]
, prependFix = [
/var prependListener;\n(?:.|\n)+\[fn, emitter\._events\[event]];\n\s\s};\n}/m,
`function prependListener(emitter, event, fn) {
if (typeof emitter.prependListener === 'function') {
return emitter.prependListener(event, fn);
} else {
// 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 (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
}
}`
]

module.exports['_stream_duplex.js'] = [
requireReplacement
Expand Down Expand Up @@ -220,6 +234,7 @@ module.exports['_stream_readable.js'] = [
, bufferShimFix
, bufferStaticMethods
, internalDirectory
, prependFix
]

module.exports['_stream_transform.js'] = [
Expand Down
11 changes: 4 additions & 7 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,16 @@ var StringDecoder;

util.inherits(Readable, Stream);

var prependListener;
if (typeof EE.prototype.prependListener === 'function') {
prependListener = function prependListener(emitter, event, fn) {
function prependListener(emitter, event, fn) {
if (typeof emitter.prependListener === 'function') {
return emitter.prependListener(event, fn);
};
} else {
prependListener = function prependListener(emitter, event, fn) {
} else {
// 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 (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
};
}
}

var Duplex;
Expand Down

0 comments on commit 25ec4c4

Please sign in to comment.