Skip to content

Commit 8716539

Browse files
committed
Fix errors in IE11
* Polyfill Number.isNaN * Don't create Symbol.asyncIterator if Symbol is not defined Fixes #364
1 parent e890201 commit 8716539

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/_stream_readable.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ function computeNewHighWaterMark(n) {
354354
function howMuchToRead(n, state) {
355355
if (n <= 0 || state.length === 0 && state.ended) return 0;
356356
if (state.objectMode) return 1;
357-
if (Number.isNaN(n)) {
357+
// Equivalent to Number.isNaN() but works in IE11
358+
if (n !== n) {
358359
// Only flow one buffer at a time
359360
if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
360361
}
@@ -941,11 +942,14 @@ Readable.prototype.wrap = function (stream) {
941942
return this;
942943
};
943944

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-
};
945+
// Only add asyncIterator if Symbol is available
946+
if (typeof Symbol === 'function') {
947+
Readable.prototype[Symbol.asyncIterator] = function () {
948+
emitExperimentalWarning('Readable[Symbol.asyncIterator]');
949+
if (ReadableAsyncIterator === undefined) ReadableAsyncIterator = require('./internal/streams/async_iterator');
950+
return new ReadableAsyncIterator(this);
951+
};
952+
}
949953

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

0 commit comments

Comments
 (0)