Skip to content

Commit f47c0e4

Browse files
authored
Update to node 10 11 (#366)
* Fix errors in IE11 * Polyfill Number.isNaN * Don't create Symbol.asyncIterator if Symbol is not defined Fixes #364 * Updated to Node 10.11.0. * Fixed browsers tests
1 parent e890201 commit f47c0e4

File tree

9 files changed

+299
-269
lines changed

9 files changed

+299
-269
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ npm install --save readable-stream
1515

1616
This package is a mirror of the streams implementations in Node.js.
1717

18-
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.10.0/docs/api/stream.html).
18+
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.11.0/docs/api/stream.html).
1919

2020
If you want to guarantee a stable streams base, regardless of what version of
2121
Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core, for background see [this blogpost](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html).

build/files.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,22 @@ function CorkedRequest(state) {
192192
/^const { emitExperimentalWarning } = require\('internal\/util'\);/m,
193193
'const { emitExperimentalWarning } = require(\'../experimentalWarning\');'
194194
]
195+
, numberIE11 = [
196+
/Number.isNaN(n)/g
197+
, 'n !== n'
198+
]
199+
, noAsyncIterators1 = [
200+
/Readable\.prototype\[Symbol\.asyncIterator\] = function\(\) \{/g
201+
, 'if (typeof Symbol === \'function\' ) {\nReadable.prototype[Symbol.asyncIterator] = function () {'
202+
]
203+
, noAsyncIterators2 = [
204+
/return new ReadableAsyncIterator\(this\);\n};/m
205+
, 'return new ReadableAsyncIterator(this);\n};\n}'
206+
]
207+
, once = [
208+
/const \{ once \} = require\('internal\/util'\);/
209+
, 'function once(callback) { let called = false; return function(...args) { if (called) return; called = true; callback(...args); }; }'
210+
]
195211

196212
module.exports['_stream_duplex.js'] = [
197213
requireReplacement
@@ -234,6 +250,9 @@ module.exports['_stream_readable.js'] = [
234250
, addUintStuff
235251
, errorsOneLevel
236252
, warnings
253+
, numberIE11
254+
, noAsyncIterators1
255+
, noAsyncIterators2
237256
]
238257

239258
module.exports['_stream_transform.js'] = [
@@ -305,6 +324,7 @@ module.exports['internal/streams/end-of-stream.js'] = [
305324
]
306325

307326
module.exports['internal/streams/pipeline.js'] = [
327+
once
308328
, errorsTwoLevel
309329
, [
310330
/require\('internal\/streams\/end-of-stream'\)/,

build/test-replacements.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ module.exports['common.js'] = [
211211
[
212212
/async_wrap\.async_hook_fields\[kCheck\] \+= 1;/,
213213
'// async_wrap.async_hook_fields[kCheck] += 1;'
214+
],
215+
[
216+
/os\.cpus\(\)/,
217+
'os.cpus().length === 0 ? [{ speed: 1000 }] : os.cpus()'
218+
],
219+
[
220+
/const buildType = process.config.target_defaults.default_configuration;/,
221+
'const buildType = \'readable-stream\';'
222+
],
223+
[
224+
/const hasCrypto = Boolean\(process.versions.openssl\);/,
225+
'const hasCrypto = !!process.browser;'
214226
]
215227
]
216228

lib/_stream_readable.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -941,11 +941,13 @@ Readable.prototype.wrap = function (stream) {
941941
return this;
942942
};
943943

944-
Readable.prototype[Symbol.asyncIterator] = function () {
945-
emitExperimentalWarning('Readable[Symbol.asyncIterator]');
946-
if (ReadableAsyncIterator === undefined) ReadableAsyncIterator = require('./internal/streams/async_iterator');
947-
return new ReadableAsyncIterator(this);
948-
};
944+
if (typeof Symbol === 'function') {
945+
Readable.prototype[Symbol.asyncIterator] = function () {
946+
emitExperimentalWarning('Readable[Symbol.asyncIterator]');
947+
if (ReadableAsyncIterator === undefined) ReadableAsyncIterator = require('./internal/streams/async_iterator');
948+
return new ReadableAsyncIterator(this);
949+
};
950+
}
949951

950952
Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
951953
// making it explicit this property is not enumerable

lib/internal/streams/pipeline.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@
55

66
var eos = void 0;
77

8-
var _require$codes = require('../../../errors').codes,
9-
ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
10-
ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
11-
128
function once(callback) {
13-
var called = false;
14-
return function (err) {
15-
if (called) return;
16-
called = true;
17-
callback(err);
9+
var called = false;return function () {
10+
if (called) return;called = true;callback.apply(undefined, arguments);
1811
};
1912
}
2013

14+
var _require$codes = require('../../../errors').codes,
15+
ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
16+
ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
17+
2118
function noop(err) {
2219
// Rethrow the error if it exists to avoid swallowing it
2320
if (err) throw err;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"test": "tap -j 4 test/parallel/*.js test/ours/*.js",
5151
"ci": "TAP=1 tap test/parallel/*.js test/ours/*.js | tee test.tap",
5252
"test-browsers": "airtap --sauce-connect --loopback airtap.local -- test/browser.js",
53-
"test-browser-local": "airtap --local -- test/browser.js",
53+
"test-browser-local": "airtap --open --local -- test/browser.js",
5454
"cover": "nyc npm test",
5555
"report": "nyc report --reporter=lcov",
5656
"update-browser-errors": "babel --presets env -o errors-browser.js errors.js"

test/common/heap.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,17 @@ var State = function () {
6868
return [expectedChild.name, 'Node / ' + expectedChild.name].includes(node.name);
6969
};
7070

71-
assert(snapshot.some(function (node) {
71+
var hasChild = snapshot.some(function (node) {
7272
return node.outgoingEdges.map(function (edge) {
7373
return edge.toNode;
7474
}).some(check);
75-
}), 'expected to find child ' + util.inspect(expectedChild) + ' ' + ('in ' + util.inspect(snapshot)));
75+
});
76+
// Don't use assert with a custom message here. Otherwise the
77+
// inspection in the message is done eagerly and wastes a lot of CPU
78+
// time.
79+
if (!hasChild) {
80+
throw new Error('expected to find child ' + (util.inspect(expectedChild) + ' in ' + util.inspect(snapshot)));
81+
}
7682
};
7783

7884
var _iteratorNormalCompletion3 = true;
@@ -134,9 +140,15 @@ var State = function () {
134140
return node.name === _expectedChild.name || node.value && node.value.constructor && node.value.constructor.name === _expectedChild.name;
135141
};
136142

137-
assert(graph.some(function (node) {
143+
// Don't use assert with a custom message here. Otherwise the
144+
// inspection in the message is done eagerly and wastes a lot of CPU
145+
// time.
146+
var hasChild = graph.some(function (node) {
138147
return node.edges.some(check);
139-
}), 'expected to find child ' + util.inspect(_expectedChild) + ' ' + ('in ' + util.inspect(snapshot)));
148+
});
149+
if (!hasChild) {
150+
throw new Error('expected to find child ' + (util.inspect(_expectedChild) + ' in ' + util.inspect(snapshot)));
151+
}
140152
};
141153

142154
var _iteratorNormalCompletion4 = true;

0 commit comments

Comments
 (0)