Skip to content

Commit e26a689

Browse files
committed
RangeError on NaN in .drop and .take
tc39/proposal-iterator-helpers#181
1 parent dccee6c commit e26a689

13 files changed

+27
-8
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var $RangeError = RangeError;
2+
3+
module.exports = function (it) {
4+
// eslint-disable-next-line no-self-compare -- NaN check
5+
if (it === it) return it;
6+
throw $RangeError('NaN is not allowed');
7+
};

packages/core-js/modules/esnext.async-iterator.drop.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var $ = require('../internals/export');
44
var apply = require('../internals/function-apply');
55
var anObject = require('../internals/an-object');
66
var getIteratorDirect = require('../internals/get-iterator-direct');
7+
var notANaN = require('../internals/not-a-nan');
78
var toPositiveInteger = require('../internals/to-positive-integer');
89
var createAsyncIteratorProxy = require('../internals/async-iterator-create-proxy');
910

@@ -36,7 +37,7 @@ var AsyncIteratorProxy = createAsyncIteratorProxy(function (Promise, args) {
3637
$({ target: 'AsyncIterator', proto: true, real: true, forced: true }, {
3738
drop: function drop(limit) {
3839
return new AsyncIteratorProxy(getIteratorDirect(this), {
39-
remaining: toPositiveInteger(limit)
40+
remaining: toPositiveInteger(notANaN(+limit))
4041
});
4142
}
4243
});

packages/core-js/modules/esnext.async-iterator.take.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var $ = require('../internals/export');
44
var apply = require('../internals/function-apply');
55
var call = require('../internals/function-call');
66
var getIteratorDirect = require('../internals/get-iterator-direct');
7+
var notANaN = require('../internals/not-a-nan');
78
var toPositiveInteger = require('../internals/to-positive-integer');
89
var createAsyncIteratorProxy = require('../internals/async-iterator-create-proxy');
910

@@ -26,7 +27,7 @@ var AsyncIteratorProxy = createAsyncIteratorProxy(function (Promise, args) {
2627
$({ target: 'AsyncIterator', proto: true, real: true, forced: true }, {
2728
take: function take(limit) {
2829
return new AsyncIteratorProxy(getIteratorDirect(this), {
29-
remaining: toPositiveInteger(limit)
30+
remaining: toPositiveInteger(notANaN(+limit))
3031
});
3132
}
3233
});

packages/core-js/modules/esnext.iterator.drop.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var apply = require('../internals/function-apply');
55
var call = require('../internals/function-call');
66
var anObject = require('../internals/an-object');
77
var getIteratorDirect = require('../internals/get-iterator-direct');
8+
var notANaN = require('../internals/not-a-nan');
89
var toPositiveInteger = require('../internals/to-positive-integer');
910
var createIteratorProxy = require('../internals/iterator-create-proxy');
1011

@@ -26,7 +27,7 @@ var IteratorProxy = createIteratorProxy(function (args) {
2627
$({ target: 'Iterator', proto: true, real: true, forced: true }, {
2728
drop: function drop(limit) {
2829
return new IteratorProxy(getIteratorDirect(this), {
29-
remaining: toPositiveInteger(limit)
30+
remaining: toPositiveInteger(notANaN(+limit))
3031
});
3132
}
3233
});

packages/core-js/modules/esnext.iterator.take.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var $ = require('../internals/export');
44
var apply = require('../internals/function-apply');
55
var anObject = require('../internals/an-object');
66
var getIteratorDirect = require('../internals/get-iterator-direct');
7+
var notANaN = require('../internals/not-a-nan');
78
var toPositiveInteger = require('../internals/to-positive-integer');
89
var createIteratorProxy = require('../internals/iterator-create-proxy');
910
var iteratorClose = require('../internals/iterator-close');
@@ -22,7 +23,7 @@ var IteratorProxy = createIteratorProxy(function (args) {
2223
$({ target: 'Iterator', proto: true, real: true, forced: true }, {
2324
take: function take(limit) {
2425
return new IteratorProxy(getIteratorDirect(this), {
25-
remaining: toPositiveInteger(limit)
26+
remaining: toPositiveInteger(notANaN(+limit))
2627
});
2728
}
2829
});

tests/pure/esnext.async-iterator.drop.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createIterator } from '../helpers/helpers';
33
import AsyncIterator from 'core-js-pure/full/async-iterator';
44

55
QUnit.test('AsyncIterator#drop', assert => {
6-
assert.expect(12);
6+
assert.expect(13);
77
const async = assert.async();
88
const { drop } = AsyncIterator.prototype;
99

@@ -29,4 +29,5 @@ QUnit.test('AsyncIterator#drop', assert => {
2929
assert.throws(() => drop.call({}, 1), TypeError);
3030
assert.throws(() => drop.call([], 1), TypeError);
3131
assert.throws(() => drop.call(createIterator([1, 2, 3]), -1), RangeError, 'negative');
32+
assert.throws(() => drop.call(createIterator([1, 2, 3]), NaN), RangeError, 'NaN');
3233
});

tests/pure/esnext.async-iterator.take.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createIterator } from '../helpers/helpers';
33
import AsyncIterator from 'core-js-pure/full/async-iterator';
44

55
QUnit.test('AsyncIterator#take', assert => {
6-
assert.expect(12);
6+
assert.expect(13);
77
const async = assert.async();
88
const { take } = AsyncIterator.prototype;
99

@@ -29,4 +29,5 @@ QUnit.test('AsyncIterator#take', assert => {
2929
assert.throws(() => take.call({}, 1), TypeError);
3030
assert.throws(() => take.call([], 1), TypeError);
3131
assert.throws(() => take.call(createIterator([1, 2, 3]), -1), RangeError, 'negative');
32+
assert.throws(() => take.call(createIterator([1, 2, 3]), NaN), RangeError, 'NaN');
3233
});

tests/pure/esnext.iterator.drop.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ QUnit.test('Iterator#drop', assert => {
1919
assert.throws(() => drop.call({}, 1), TypeError);
2020
assert.throws(() => drop.call([], 1), TypeError);
2121
assert.throws(() => drop.call(createIterator([1, 2, 3]), -1), RangeError, 'negative');
22+
assert.throws(() => drop.call(createIterator([1, 2, 3]), NaN), RangeError, 'NaN');
2223
});

tests/pure/esnext.iterator.take.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ QUnit.test('Iterator#take', assert => {
1919
assert.throws(() => take.call({}, 1), TypeError);
2020
assert.throws(() => take.call([], 1), TypeError);
2121
assert.throws(() => take.call(createIterator([1, 2, 3]), -1), RangeError, 'negative');
22+
assert.throws(() => take.call(createIterator([1, 2, 3]), NaN), RangeError, 'NaN');
2223
});

tests/tests/esnext.async-iterator.drop.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createIterator } from '../helpers/helpers';
22

33
QUnit.test('AsyncIterator#drop', assert => {
4-
assert.expect(14);
4+
assert.expect(15);
55
const async = assert.async();
66
const { drop } = AsyncIterator.prototype;
77

@@ -29,4 +29,5 @@ QUnit.test('AsyncIterator#drop', assert => {
2929
assert.throws(() => drop.call({}, 1), TypeError);
3030
assert.throws(() => drop.call([], 1), TypeError);
3131
assert.throws(() => drop.call(createIterator([1, 2, 3]), -1), RangeError, 'negative');
32+
assert.throws(() => drop.call(createIterator([1, 2, 3]), NaN), RangeError, 'NaN');
3233
});

0 commit comments

Comments
 (0)