Skip to content

Commit 25ec4c4

Browse files
committed
fix prepend
1 parent e8ee016 commit 25ec4c4

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

build/files.js

+15
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ const headRegexp = /(^module.exports = \w+;?)/m
175175
/require\('internal\/streams\/BufferList'\)/,
176176
'require(\'./internal/streams/BufferList\')'
177177
]
178+
, prependFix = [
179+
/var prependListener;\n(?:.|\n)+\[fn, emitter\._events\[event]];\n\s\s};\n}/m,
180+
`function prependListener(emitter, event, fn) {
181+
if (typeof emitter.prependListener === 'function') {
182+
return emitter.prependListener(event, fn);
183+
} else {
184+
// This is a hack to make sure that our error handler is attached before any
185+
// userland ones. NEVER DO THIS. This is here only because this code needs
186+
// to continue to work with older versions of Node.js that do not include
187+
// the prependListener() method. The goal is to eventually remove this hack.
188+
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]];
189+
}
190+
}`
191+
]
178192

179193
module.exports['_stream_duplex.js'] = [
180194
requireReplacement
@@ -220,6 +234,7 @@ module.exports['_stream_readable.js'] = [
220234
, bufferShimFix
221235
, bufferStaticMethods
222236
, internalDirectory
237+
, prependFix
223238
]
224239

225240
module.exports['_stream_transform.js'] = [

lib/_stream_readable.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,16 @@ var StringDecoder;
5656

5757
util.inherits(Readable, Stream);
5858

59-
var prependListener;
60-
if (typeof EE.prototype.prependListener === 'function') {
61-
prependListener = function prependListener(emitter, event, fn) {
59+
function prependListener(emitter, event, fn) {
60+
if (typeof emitter.prependListener === 'function') {
6261
return emitter.prependListener(event, fn);
63-
};
64-
} else {
65-
prependListener = function prependListener(emitter, event, fn) {
62+
} else {
6663
// This is a hack to make sure that our error handler is attached before any
6764
// userland ones. NEVER DO THIS. This is here only because this code needs
6865
// to continue to work with older versions of Node.js that do not include
6966
// the prependListener() method. The goal is to eventually remove this hack.
7067
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]];
71-
};
68+
}
7269
}
7370

7471
var Duplex;

0 commit comments

Comments
 (0)