Skip to content

Commit 80f685f

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

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
@@ -3,6 +3,7 @@
33
var $ = require('../internals/export');
44
var apply = require('../internals/function-apply');
55
var anObject = require('../internals/an-object');
6+
var notANaN = require('../internals/not-a-nan');
67
var toPositiveInteger = require('../internals/to-positive-integer');
78
var createAsyncIteratorProxy = require('../internals/async-iterator-create-proxy');
89

@@ -36,7 +37,7 @@ $({ target: 'AsyncIterator', proto: true, real: true, forced: true }, {
3637
drop: function drop(limit) {
3738
return new AsyncIteratorProxy({
3839
iterator: anObject(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 anObject = require('../internals/an-object');
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

@@ -27,7 +28,7 @@ $({ target: 'AsyncIterator', proto: true, real: true, forced: true }, {
2728
take: function take(limit) {
2829
return new AsyncIteratorProxy({
2930
iterator: anObject(this),
30-
remaining: toPositiveInteger(limit)
31+
remaining: toPositiveInteger(notANaN(+limit))
3132
});
3233
}
3334
});

packages/core-js/modules/esnext.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 call = require('../internals/function-call');
66
var anObject = require('../internals/an-object');
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

@@ -26,7 +27,7 @@ $({ target: 'Iterator', proto: true, real: true, forced: true }, {
2627
drop: function drop(limit) {
2728
return new IteratorProxy({
2829
iterator: anObject(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
@@ -3,6 +3,7 @@
33
var $ = require('../internals/export');
44
var apply = require('../internals/function-apply');
55
var anObject = require('../internals/an-object');
6+
var notANaN = require('../internals/not-a-nan');
67
var toPositiveInteger = require('../internals/to-positive-integer');
78
var createIteratorProxy = require('../internals/iterator-create-proxy');
89
var iteratorClose = require('../internals/iterator-close');
@@ -22,7 +23,7 @@ $({ target: 'Iterator', proto: true, real: true, forced: true }, {
2223
take: function take(limit) {
2324
return new IteratorProxy({
2425
iterator: anObject(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)