throw a RangeError on finite unsafe integer limit in Iterator.prototype.{ drop, take }

https://github.com/tc39/ecma262/pull/3776
This commit is contained in:
Denis Pushkarev
2026-06-28 16:56:51 +07:00
parent 9a86ea4f81
commit 6349b6aa7d
9 changed files with 80 additions and 14 deletions
+14 -10
View File
@@ -718,11 +718,13 @@ export const data = {
// with changes related to the new iteration closing approach on early error
// https://github.com/tc39/ecma262/pull/3467
// https://bugs.webkit.org/show_bug.cgi?id=291195
bun: '1.2.11', // '1.2.4', // '1.1.31',
chrome: '135', // '122',
deno: '2.2.5', // '1.38.1',
firefox: '141', // '131',
safari: '26.0', // 18.4',
// with changes related to changed limit validation
// https://github.com/tc39/ecma262/pull/3776
// bun: '1.2.11', // '1.2.4', // '1.1.31',
chrome: '150', // '135', // '122',
// deno: '2.2.5', // '1.38.1',
// firefox: '141', // '131',
// safari: '26.0', // 18.4',
},
'es.iterator.every': {
// with changes related to the new iteration closing approach on early error
@@ -813,11 +815,13 @@ export const data = {
// with changes related to the new iteration closing approach on early error
// https://github.com/tc39/ecma262/pull/3467
// https://bugs.webkit.org/show_bug.cgi?id=291195
bun: '1.2.11', // '1.2.4', // '1.1.31',
chrome: '135', // '122',
deno: '2.2.5', // '1.38.1',
firefox: '141', // '131',
safari: '26.0', // 18.4',
// with changes related to changed limit validation
// https://github.com/tc39/ecma262/pull/3776
// bun: '1.2.11', // '1.2.4', // '1.1.31',
chrome: '150', // '135', // '122',
// deno: '2.2.5', // '1.38.1',
// firefox: '141', // '131',
// safari: '26.0', // 18.4',
},
'es.iterator.to-array': {
bun: '1.1.31',
+16 -1
View File
@@ -11,11 +11,23 @@ var iteratorHelperThrowsOnInvalidIterator = require('../internals/iterator-helpe
var iteratorHelperWithoutClosingOnEarlyError = require('../internals/iterator-helper-without-closing-on-early-error');
var IS_PURE = require('../internals/is-pure');
var $RangeError = RangeError;
var $Infinity = Infinity;
var DROP_WITHOUT_THROWING_ON_INVALID_ITERATOR = !IS_PURE && !iteratorHelperThrowsOnInvalidIterator('drop', 0);
var dropWithoutClosingOnEarlyError = !IS_PURE && !DROP_WITHOUT_THROWING_ON_INVALID_ITERATOR
&& iteratorHelperWithoutClosingOnEarlyError('drop', RangeError);
var FORCED = IS_PURE || DROP_WITHOUT_THROWING_ON_INVALID_ITERATOR || dropWithoutClosingOnEarlyError;
var FORCED = IS_PURE || DROP_WITHOUT_THROWING_ON_INVALID_ITERATOR || dropWithoutClosingOnEarlyError || !function () {
try {
// eslint-disable-next-line es/no-iterator, es/no-iterator-prototype-drop -- detection
Iterator.prototype.drop.call({
next: function () { return { done: true }; }
}, 0x20000000000000);
} catch (error) {
return error instanceof $RangeError;
}
}();
var IteratorProxy = createIteratorProxy(function () {
var iterator = this.iterator;
@@ -40,6 +52,9 @@ $({ target: 'Iterator', proto: true, real: true, forced: FORCED }, {
var remaining;
try {
remaining = toPositiveInteger(notANaN(+limit));
if (remaining > 0x1FFFFFFFFFFFFF && remaining !== $Infinity) {
throw new $RangeError('The argument should be a safe integer');
}
} catch (error) {
iteratorClose(this, 'throw', error);
}
+16 -1
View File
@@ -11,11 +11,23 @@ var iteratorHelperThrowsOnInvalidIterator = require('../internals/iterator-helpe
var iteratorHelperWithoutClosingOnEarlyError = require('../internals/iterator-helper-without-closing-on-early-error');
var IS_PURE = require('../internals/is-pure');
var $RangeError = RangeError;
var $Infinity = Infinity;
var TAKE_WITHOUT_THROWING_ON_INVALID_ITERATOR = !IS_PURE && !iteratorHelperThrowsOnInvalidIterator('take', 1);
var takeWithoutClosingOnEarlyError = !IS_PURE && !TAKE_WITHOUT_THROWING_ON_INVALID_ITERATOR
&& iteratorHelperWithoutClosingOnEarlyError('take', RangeError);
var FORCED = IS_PURE || TAKE_WITHOUT_THROWING_ON_INVALID_ITERATOR || takeWithoutClosingOnEarlyError;
var FORCED = IS_PURE || TAKE_WITHOUT_THROWING_ON_INVALID_ITERATOR || takeWithoutClosingOnEarlyError || !function () {
try {
// eslint-disable-next-line es/no-iterator, es/no-iterator-prototype-take -- detection
Iterator.prototype.take.call({
next: function () { return { done: true }; }
}, 0x20000000000000);
} catch (error) {
return error instanceof $RangeError;
}
}();
var IteratorProxy = createIteratorProxy(function () {
var iterator = this.iterator;
@@ -36,6 +48,9 @@ $({ target: 'Iterator', proto: true, real: true, forced: FORCED }, {
var remaining;
try {
remaining = toPositiveInteger(notANaN(+limit));
if (remaining > 0x1FFFFFFFFFFFFF && remaining !== $Infinity) {
throw new $RangeError('The argument should be a safe integer');
}
} catch (error) {
iteratorClose(this, 'throw', error);
}