es-iterator-helpers
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -15,5 +15,5 @@ 'use strict'; | ||
var isIteratorRecord = require('es-abstract/helpers/records/iterator-record'); | ||
var some = require('es-abstract/helpers/some'); | ||
var every = require('es-abstract/helpers/every'); | ||
var callBound = require('call-bind/callBound'); | ||
var callBound = require('call-bound'); | ||
@@ -31,3 +31,3 @@ var $indexOf = callBound('Array.prototype.indexOf'); | ||
module.exports = function IteratorZip(iters, mode, padding, finishResults) { | ||
if (!IsArray(iters) || !some(iters, isIteratorRecord)) { | ||
if (!IsArray(iters) || !every(iters, isIteratorRecord)) { | ||
throw new $TypeError('`iters` must be a List of IteratorRecords'); | ||
@@ -34,0 +34,0 @@ } |
@@ -8,2 +8,21 @@ # Changelog | ||
## [v1.2.1](https://github.com/es-shims/iterator-helpers/compare/v1.2.0...v1.2.1) - 2024-12-20 | ||
### Commits | ||
- [Tests] `Iterator.concat`: add most of the tests from https://github.com/tc39/test262/pull/4326 [`2e340da`](https://github.com/es-shims/iterator-helpers/commit/2e340daf021139ea41dc828c7f99452114db8561) | ||
- [Fix] `Iterator.concat`: rewrite implementation to match updated spec text [`1a70fd3`](https://github.com/es-shims/iterator-helpers/commit/1a70fd33ab81738ad2b748812a431d51e0c4d758) | ||
- [Fix] `IteratorZip` AO: allow an empty list of iterators [`265e566`](https://github.com/es-shims/iterator-helpers/commit/265e5664dade59e2faa5d7d2e203b92cd0af5c35) | ||
- [actions] split out node 10-20, and 20+ [`3cc9db0`](https://github.com/es-shims/iterator-helpers/commit/3cc9db03118e2b4b6432e262e7936a7e2f3074c4) | ||
- [Fix] `IteratorHelperPrototype`: in pre-proto envs, use same `.return` impl [`da02ab6`](https://github.com/es-shims/iterator-helpers/commit/da02ab656dce1c4f73355290a3bd9e4c25ccc3b6) | ||
- [Deps] update `call-bind`, `es-abstract`, `get-intrinsic`, `gopd`, `has-proto`, `internal-slot`, `iterator.prototype`, `safe-array-concat` [`e9eefab`](https://github.com/es-shims/iterator-helpers/commit/e9eefab99fb496f9a4600193126c69c321394d42) | ||
- [Tests] `Iterator.zip`: nullish non-function Symbol.iterator does not throw [`c6b0705`](https://github.com/es-shims/iterator-helpers/commit/c6b0705e2b601c1c8d412679eca4fe4618051d8f) | ||
- [Refactor] use `call-bound` directly [`92afc5a`](https://github.com/es-shims/iterator-helpers/commit/92afc5a7ed014b5e2b52db1b1a6a99d16f50d5d2) | ||
- [Deps] update `gopd`, `has-proto`, `has-symbols` [`7f8a1c0`](https://github.com/es-shims/iterator-helpers/commit/7f8a1c0049dfd649bea9a707b9c451ba7e9f3b0e) | ||
- [readme] add missing info for `Iterator.zip`, `Iterator.zipKeyed` [`dd80b2f`](https://github.com/es-shims/iterator-helpers/commit/dd80b2f1718092219e94e24afdc1737f062e3df4) | ||
- [Dev Deps] update `@es-shims/api` [`1e9857c`](https://github.com/es-shims/iterator-helpers/commit/1e9857c497f8f4e6053c9adb7dddb98b6800c628) | ||
- [Deps] update `es-abstract` [`c8157da`](https://github.com/es-shims/iterator-helpers/commit/c8157da5194372ddc968e0f512d0740544752d30) | ||
- [Deps] update `es-abstract` [`256de0e`](https://github.com/es-shims/iterator-helpers/commit/256de0e1aa45d6d0ad12a19ef04491816bcb7288) | ||
- [Dev Deps] update `object-inspect` [`2f8544b`](https://github.com/es-shims/iterator-helpers/commit/2f8544b7baa80174e7368d475a4e3fa577418938) | ||
## [v1.2.0](https://github.com/es-shims/iterator-helpers/compare/v1.1.0...v1.2.0) - 2024-11-04 | ||
@@ -10,0 +29,0 @@ |
@@ -14,3 +14,2 @@ 'use strict'; | ||
var IteratorStepValue = require('es-abstract/2024/IteratorStepValue'); | ||
var ThrowCompletion = require('es-abstract/2024/ThrowCompletion'); | ||
var Type = require('es-abstract/2024/Type'); | ||
@@ -21,6 +20,2 @@ | ||
var callBound = require('call-bind/callBound'); | ||
var $indexOf = callBound('Array.prototype.indexOf'); | ||
var $splice = callBound('Array.prototype.splice'); | ||
var iterHelperProto = require('../IteratorHelperPrototype'); | ||
@@ -56,4 +51,34 @@ | ||
var openIters = []; // step 3 | ||
var sentinel = {}; | ||
var iterablesIndex = 0; | ||
var iteratorRecord; | ||
var innerAlive = false; | ||
var closure = function () { // step 3 | ||
if (iterablesIndex >= iterables.length) { | ||
return sentinel; | ||
} | ||
var iterable = iterables[iterablesIndex]; // step 3.a | ||
if (!innerAlive) { | ||
var iter = Call(iterable['[[OpenMethod]]'], iterable['[[Iterable]]']); // step 3.a.i | ||
if (Type(iter) !== 'Object') { | ||
throw new $TypeError('`Iterator.concat` iterator method did not return an object'); // step 3.a.ii | ||
} | ||
iteratorRecord = GetIteratorDirect(iter); // step 3.a.iii | ||
innerAlive = true; // step 3.a.iv | ||
} | ||
if (innerAlive) { // step 3.a.v | ||
var innerValue = IteratorStepValue(iteratorRecord); // step 3.a.v.1 | ||
if (iteratorRecord['[[Done]]']) { // step 3.a.v.2 | ||
innerAlive = false; // step 3.a.v.2.a | ||
} else { // step 3.a.v.3 | ||
// 1. Let completion be Completion(Yield(innerValue)). | ||
return innerValue; // step 3.a.v.3.a | ||
} | ||
} | ||
iterablesIndex += 1; | ||
return closure(); | ||
}; | ||
var closeIfAbrupt = function (abruptCompletion) { | ||
@@ -63,5 +88,7 @@ if (!(abruptCompletion instanceof CompletionRecord)) { | ||
} | ||
if (openIters.length > 0) { | ||
iterablesIndex = iterables.length; | ||
innerAlive = false; | ||
if (iteratorRecord) { | ||
IteratorCloseAll( | ||
openIters, | ||
[iteratorRecord], | ||
abruptCompletion | ||
@@ -72,47 +99,2 @@ ); | ||
var index = 0; | ||
var closure = function () { // step 4 | ||
if (index < iterables.length) { | ||
// forEach(iterables, function (iterable) { // step 4.a | ||
var iteratorRecord; | ||
if (openIters.length === 0) { | ||
var iterable = iterables[index]; | ||
var iter = Call(iterable['[[OpenMethod]]'], iterable['[[Iterable]]']); // step 4.a.i | ||
if (Type(iter) !== 'Object') { | ||
closeIfAbrupt(ThrowCompletion(new $TypeError('???'))); // step 4.a.ii | ||
} | ||
iteratorRecord = GetIteratorDirect(iter); // step 4.a.iii | ||
iteratorRecord.obj = iterable['[[Iterable]]']; | ||
openIters[openIters.length] = iteratorRecord; // step 4.a.iv | ||
} else { | ||
iteratorRecord = openIters[0]; | ||
} | ||
// var innerAlive = true; // step 4.a.v | ||
// while (innerAlive) { // step 4.a.vi | ||
{ // eslint-disable-line no-lone-blocks | ||
// step 4.a.vi.3.a | ||
var innerValue; | ||
try { | ||
innerValue = IteratorStepValue(iteratorRecord); // step 5.b.ix.4.a | ||
} catch (e) { | ||
// innerAlive = false; | ||
$splice(openIters, $indexOf(openIters, iteratorRecord), 1); // step 4.a.vi.2.a | ||
index += 1; | ||
closeIfAbrupt(ThrowCompletion(e)); // step 4.a.vi.3.b | ||
} | ||
if (iteratorRecord['[[Done]]']) { | ||
// innerAlive = false; | ||
$splice(openIters, $indexOf(openIters, iteratorRecord), 1); | ||
index += 1; | ||
return closure(); | ||
} | ||
return innerValue; // // step 4.a.vi.3.a | ||
} | ||
// }); | ||
} | ||
// return ReturnCompletion(undefined); // step 4.b | ||
return sentinel; | ||
}; | ||
SLOT.set(closure, '[[Sentinel]]', sentinel); // for the userland implementation | ||
@@ -119,0 +101,0 @@ SLOT.set(closure, '[[CloseIfAbrupt]]', closeIfAbrupt); // for the userland implementation |
@@ -9,6 +9,2 @@ 'use strict'; | ||
var callBound = require('call-bind/callBound'); | ||
var $push = callBound('Array.prototype.push'); | ||
module.exports = function toArray() { | ||
@@ -35,4 +31,4 @@ if (this instanceof toArray) { | ||
} | ||
$push(items, value); // step 5.d | ||
items[items.length] = value; // step 5.d | ||
} | ||
}; |
@@ -16,2 +16,3 @@ 'use strict'; | ||
var ThrowCompletion = require('es-abstract/2024/ThrowCompletion'); | ||
var ToPropertyDescriptor = require('es-abstract/2024/ToPropertyDescriptor'); | ||
var Type = require('es-abstract/2024/Type'); | ||
@@ -47,6 +48,6 @@ | ||
if (mode === 'longest') { | ||
paddingOption = Get(options, 'padding'); // step 7 | ||
if (mode === 'longest') { // step 7 | ||
paddingOption = Get(options, 'padding'); // step 7.a | ||
if (typeof paddingOption !== 'undefined' && Type(paddingOption) !== 'Object') { | ||
throw new $TypeError('`padding` option must be an Object'); // step 7.1 | ||
throw new $TypeError('`padding` option must be an Object'); // step 7.b | ||
} | ||
@@ -66,3 +67,3 @@ } | ||
try { | ||
desc = gOPD(iterables, key); // step 12.a | ||
desc = ToPropertyDescriptor(gOPD(iterables, key)); // step 12.a | ||
} catch (e) { | ||
@@ -98,4 +99,3 @@ IfAbruptCloseIterators(ThrowCompletion(e), iters); // step 12.b | ||
} catch (e) { | ||
// step 12.c.iv.3 | ||
// 3. IfAbruptCloseIterators(e, iters). | ||
IfAbruptCloseIterators(ThrowCompletion(e), iters); // step 12.c.iv.3 | ||
} | ||
@@ -102,0 +102,0 @@ iters[iters.length] = iter; // step 12.c.iv.4 |
@@ -10,3 +10,3 @@ 'use strict'; | ||
var iterProto = require('iterator.prototype'); | ||
var callBound = require('call-bind/callBound'); | ||
var callBound = require('call-bound'); | ||
@@ -13,0 +13,0 @@ var $isPrototypeOf = callBound('Object.prototype.isPrototypeOf'); |
@@ -12,6 +12,24 @@ 'use strict'; | ||
var IteratorCloseAll = require('../aos/IteratorCloseAll'); | ||
var NormalCompletion = require('es-abstract/2024/NormalCompletion'); | ||
var ReturnCompletion = require('../aos/ReturnCompletion'); | ||
var implementation; | ||
var o = { // in an object, for name inference | ||
'return': function () { | ||
var O = this; // step 1 | ||
SLOT.assert(O, '[[UnderlyingIterators]]'); // step 2 | ||
SLOT.assert(O, '[[GeneratorState]]'); // step 3 | ||
if (SLOT.get(O, '[[GeneratorState]]') === 'suspendedStart') { // step 4 | ||
SLOT.set(O, '[[GeneratorState]]', 'completed'); // step 4.a | ||
IteratorCloseAll(SLOT.get(O, '[[UnderlyingIterators]]'), ReturnCompletion(void undefined)); // step 4.c | ||
return CreateIterResultObject(void undefined, true); // step 4.d | ||
} | ||
var C = ReturnCompletion(void undefined); // step 5 | ||
return GeneratorResumeAbrupt(O, C, 'Iterator Helper'); // step 6 | ||
} | ||
}; | ||
if (hasProto) { | ||
@@ -23,19 +41,3 @@ implementation = { | ||
}, | ||
'return': function () { | ||
var O = this; // step 1 | ||
SLOT.assert(O, '[[UnderlyingIterators]]'); // step 2 | ||
SLOT.assert(O, '[[GeneratorState]]'); // step 3 | ||
if (SLOT.get(O, '[[GeneratorState]]') === 'suspendedStart') { // step 4 | ||
SLOT.set(O, '[[GeneratorState]]', 'completed'); // step 4.a | ||
IteratorCloseAll(SLOT.get(O, '[[UnderlyingIterators]]'), NormalCompletion('unused')); // step 4.c | ||
return CreateIterResultObject(void undefined, true); // step 4.d | ||
} | ||
var C = ReturnCompletion(void undefined); // step 5 | ||
return GeneratorResumeAbrupt(O, C, 'Iterator Helper'); // step 6 | ||
} | ||
'return': o['return'] | ||
}; | ||
@@ -51,8 +53,5 @@ setToStringTag(implementation, 'Iterator Helper'); | ||
}; | ||
implementation['return'] = function () { | ||
var C = ReturnCompletion(void undefined); // step 1 | ||
return GeneratorResumeAbrupt(this, C, 'Iterator Helper'); | ||
}; | ||
implementation['return'] = o['return']; | ||
} | ||
module.exports = implementation; |
{ | ||
"name": "es-iterator-helpers", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "An ESnext spec-compliant iterator helpers shim/polyfill/replacement that works as far down as ES3.", | ||
@@ -149,20 +149,21 @@ "main": "index.json", | ||
"dependencies": { | ||
"call-bind": "^1.0.7", | ||
"call-bind": "^1.0.8", | ||
"call-bound": "^1.0.3", | ||
"define-properties": "^1.2.1", | ||
"es-abstract": "^1.23.3", | ||
"es-abstract": "^1.23.6", | ||
"es-errors": "^1.3.0", | ||
"es-set-tostringtag": "^2.0.3", | ||
"function-bind": "^1.1.2", | ||
"get-intrinsic": "^1.2.4", | ||
"get-intrinsic": "^1.2.6", | ||
"globalthis": "^1.0.4", | ||
"gopd": "^1.0.1", | ||
"gopd": "^1.2.0", | ||
"has-property-descriptors": "^1.0.2", | ||
"has-proto": "^1.0.3", | ||
"has-symbols": "^1.0.3", | ||
"internal-slot": "^1.0.7", | ||
"iterator.prototype": "^1.1.3", | ||
"safe-array-concat": "^1.1.2" | ||
"has-proto": "^1.2.0", | ||
"has-symbols": "^1.1.0", | ||
"internal-slot": "^1.1.0", | ||
"iterator.prototype": "^1.1.4", | ||
"safe-array-concat": "^1.1.3" | ||
}, | ||
"devDependencies": { | ||
"@es-shims/api": "^3.0.1", | ||
"@es-shims/api": "^3.0.2", | ||
"@ljharb/eslint-config": "^21.1.1", | ||
@@ -185,3 +186,3 @@ "auto-changelog": "^2.5.0", | ||
"nyc": "^10.3.2", | ||
"object-inspect": "^1.13.2", | ||
"object-inspect": "^1.13.3", | ||
"safe-publish-latest": "^2.0.0", | ||
@@ -188,0 +189,0 @@ "tape": "^5.9.0" |
@@ -24,2 +24,4 @@ # es-iterator-helpers <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
- [`Iterator.from`](https://tc39.es/proposal-iterator-helpers/#sec-iterator.from) | ||
- [`Iterator.zip`](https://tc39.es/proposal-joint-iteration/#sec-iterator.zip) | ||
- [`Iterator.zipKeyed`](https://tc39.es/proposal-joint-iteration/#sec-iterator.zipkeyed) | ||
- [`Iterator.prototype.constructor`](https://tc39.es/proposal-iterator-helpers/#sec-iteratorprototype.constructor) | ||
@@ -42,3 +44,3 @@ - [`Iterator.prototype.drop`](https://tc39.es/proposal-iterator-helpers/#sec-iteratorprototype.drop) | ||
- node < v22, Chrome < v122, Safari <= v17.1, Firefox <= v125: not implemented | ||
- all environments lack Iterator.concat | ||
- all environments lack Iterator.concat, Iterator.zip, Iterator.zipKeyed | ||
@@ -45,0 +47,0 @@ ## Getting started |
@@ -12,2 +12,3 @@ 'use strict'; | ||
var mockProperty = require('mock-property'); | ||
var hasPropertyDescriptors = require('has-property-descriptors')(); | ||
@@ -43,2 +44,4 @@ var index = require('../Iterator.concat'); | ||
t.deepEqual(concat().next(), { value: undefined, done: true }, 'no arguments -> empty iterator'); | ||
t.test('actual iteration', { skip: !hasSymbols }, function (st) { | ||
@@ -49,5 +52,15 @@ forEach(v.nonFunctions, function (nonFunction) { | ||
st['throws']( | ||
function () { concat([], badIterable, []); }, | ||
TypeError, | ||
debug(badIterable) + '[Symbol.iterator] is not a function' | ||
); | ||
}); | ||
forEach(v.primitives, function (nonObject) { | ||
var badIterable = {}; | ||
badIterable[Symbol.iterator] = function () { return nonObject; }; | ||
st['throws']( | ||
function () { concat([], badIterable, []).next(); }, | ||
TypeError, | ||
debug(badIterable) + ' is not a function' | ||
debug(badIterable) + '[Symbol.iterator] does not return an object' | ||
); | ||
@@ -96,2 +109,433 @@ }); | ||
st.test('test262: test/built-ins/Iterator/concat/arguments-checked-in-order', { skip: !hasPropertyDescriptors }, function (s2t) { | ||
var getIterator = 0; | ||
var iterable1 = {}; | ||
Object.defineProperty(iterable1, Symbol.iterator, { | ||
get: function () { | ||
getIterator += 1; | ||
return function () { | ||
throw new EvalError(); | ||
}; | ||
} | ||
}); | ||
var iterable2 = {}; | ||
Object.defineProperty(iterable2, Symbol.iterator, { | ||
get: function () { | ||
throw new EvalError(); | ||
} | ||
}); | ||
s2t.equal(getIterator, 0); | ||
s2t['throws'](function () { concat(iterable1, null, iterable2); }, TypeError); | ||
s2t.equal(getIterator, 1); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/fresh-iterator-result', function (s2t) { | ||
var oldIterResult = { | ||
done: false, | ||
value: 123 | ||
}; | ||
var testIterator1 = { | ||
next: function () { | ||
return oldIterResult; | ||
} | ||
}; | ||
var iterable = {}; | ||
iterable[Symbol.iterator] = function () { | ||
return testIterator1; | ||
}; | ||
var iterator = concat(iterable); | ||
var iterResult = iterator.next(); | ||
s2t.equal(iterResult.done, false); | ||
s2t.equal(iterResult.value, 123); | ||
s2t.notEqual(iterResult, oldIterResult); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/get-iterator-method-only-once', { skip: !hasPropertyDescriptors }, function (s2t) { | ||
var iteratorGets = 0; | ||
var iteratorCalls = 0; | ||
var array = [1, 2, 3]; | ||
function CountingIterable() {} | ||
Object.defineProperty( | ||
CountingIterable.prototype, | ||
Symbol.iterator, | ||
{ | ||
get: function () { | ||
iteratorGets += 1; | ||
return function () { | ||
iteratorCalls += 1; | ||
return array[Symbol.iterator](); | ||
}; | ||
} | ||
} | ||
); | ||
var iterable = new CountingIterable(); | ||
s2t.equal(iteratorGets, 0); | ||
s2t.equal(iteratorCalls, 0); | ||
var iter = concat(iterable); | ||
s2t.equal(iteratorGets, 1); | ||
s2t.equal(iteratorCalls, 0); | ||
testIterator(iter, array, s2t, 'iterating over the iterator calls the iterator function once'); | ||
s2t.equal(iteratorGets, 1); | ||
s2t.equal(iteratorCalls, 1); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/get-iterator-method-throws', { skip: !hasPropertyDescriptors }, function (s2t) { | ||
var iterable = {}; | ||
Object.defineProperty(iterable, Symbol.iterator, { | ||
get: function () { | ||
throw new EvalError(); | ||
} | ||
}); | ||
s2t['throws'](function () { concat(iterable); }, EvalError); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/inner-iterator-created-in-order', function (s2t) { | ||
var calledIterator = []; | ||
var iterable1 = {}; | ||
iterable1[Symbol.iterator] = function () { | ||
calledIterator.push('iterable1'); | ||
return [1][Symbol.iterator](); | ||
}; | ||
var iterable2 = {}; | ||
iterable2[Symbol.iterator] = function () { | ||
calledIterator.push('iterable2'); | ||
return [2][Symbol.iterator](); | ||
}; | ||
var iterator = concat(iterable1, iterable2); | ||
s2t.deepEqual(calledIterator, []); | ||
s2t.deepEqual(iterator.next(), { done: false, value: 1 }); | ||
s2t.deepEqual(calledIterator, ['iterable1']); | ||
s2t.deepEqual(iterator.next(), { done: false, value: 2 }); | ||
s2t.deepEqual(calledIterator, ['iterable1', 'iterable2']); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/next-method-called-with-zero-arguments', function (s2t) { | ||
var nextCalled = 0; | ||
var testIterator1 = { | ||
next: function () { | ||
nextCalled += 1; | ||
s2t.equal(arguments.length, 0); | ||
return { | ||
done: false, | ||
value: 0 | ||
}; | ||
} | ||
}; | ||
var iterable = {}; | ||
iterable[Symbol.iterator] = function () { | ||
return testIterator1; | ||
}; | ||
var iterator = concat(iterable); | ||
s2t.equal(nextCalled, 0); | ||
iterator.next(); | ||
s2t.equal(nextCalled, 1); | ||
iterator.next(1); | ||
s2t.equal(nextCalled, 2); | ||
iterator.next(1, 2); | ||
s2t.equal(nextCalled, 3); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/next-method-returns-non-object', function (s2t) { | ||
var nonObjectIterator = { | ||
next: function () { | ||
return null; | ||
} | ||
}; | ||
var iterable = {}; | ||
iterable[Symbol.iterator] = function () { | ||
return nonObjectIterator; | ||
}; | ||
var iterator = concat(iterable); | ||
s2t['throws'](function () { iterator.next(); }, TypeError); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/next-method-returns-throwing-done', { skip: !hasPropertyDescriptors }, function (s2t) { | ||
var throwingIterator = { | ||
next: function () { | ||
var result = { done: null, value: 1 }; | ||
Object.defineProperty(result, 'done', { | ||
get: function () { | ||
throw new EvalError(); | ||
} | ||
}); | ||
return result; | ||
}, | ||
'return': function () { | ||
throw new Error(); | ||
} | ||
}; | ||
var iterable = {}; | ||
iterable[Symbol.iterator] = function () { | ||
return throwingIterator; | ||
}; | ||
var iterator = concat(iterable); | ||
s2t['throws'](function () { iterator.next(); }, EvalError); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/next-method-returns-throwing-value-done', { skip: !hasPropertyDescriptors }, function (s2t) { | ||
function ReturnCalledError() {} | ||
function ValueGetterError() {} | ||
var throwingIterator = { | ||
next: function () { | ||
var result = { value: null, done: true }; | ||
Object.defineProperty(result, 'value', { | ||
get: function () { | ||
throw new ValueGetterError(); | ||
} | ||
}); | ||
return result; | ||
}, | ||
'return': function () { | ||
throw new ReturnCalledError(); | ||
} | ||
}; | ||
var iterable = {}; | ||
iterable[Symbol.iterator] = function () { | ||
return throwingIterator; | ||
}; | ||
var iterator = concat(iterable); | ||
var iterResult = iterator.next(); | ||
s2t.equal(iterResult.done, true); | ||
s2t.equal(iterResult.value, undefined); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/next-method-returns-throwing-value', { skip: !hasPropertyDescriptors }, function (s2t) { | ||
var throwingIterator = { | ||
next: function () { | ||
var result = { value: null, done: false }; | ||
Object.defineProperty(result, 'value', { | ||
get: function () { | ||
throw new EvalError(); | ||
} | ||
}); | ||
return result; | ||
}, | ||
'return': function () { | ||
throw new Error(); | ||
} | ||
}; | ||
var iterable = {}; | ||
iterable[Symbol.iterator] = function () { | ||
return throwingIterator; | ||
}; | ||
var iterator = concat(iterable); | ||
s2t['throws'](function () { iterator.next(); }, EvalError); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/next-method-throws', function (s2t) { | ||
var throwingIterator = { | ||
next: function () { | ||
throw new EvalError(); | ||
} | ||
}; | ||
var iterable = {}; | ||
iterable[Symbol.iterator] = function () { | ||
return throwingIterator; | ||
}; | ||
var iterator = concat(iterable); | ||
s2t['throws'](function () { iterator.next(); }, EvalError); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/return-is-not-forwarded-after-exhaustion', function (s2t) { | ||
var testIterator1 = { | ||
next: function () { | ||
return { | ||
done: true, | ||
value: undefined | ||
}; | ||
}, | ||
'return': function () { | ||
throw new EvalError(); | ||
} | ||
}; | ||
var iterable = {}; | ||
iterable[Symbol.iterator] = function () { | ||
return testIterator1; | ||
}; | ||
var iterator = concat(iterable); | ||
iterator.next(); | ||
iterator['return'](); | ||
s2t.end(); | ||
}); | ||
t.test('test262: test/built-ins/Iterator/concat/return-is-not-forwarded-before-initial-start', function (s2t) { | ||
var testIterator1 = { | ||
next: function () { | ||
return { | ||
done: false, | ||
value: 1 | ||
}; | ||
}, | ||
'return': function () { | ||
throw new EvalError(); | ||
} | ||
}; | ||
var iterable = {}; | ||
iterable[Symbol.iterator] = function () { | ||
return testIterator1; | ||
}; | ||
var iterator = concat(iterable); | ||
iterator['return'](); | ||
iterator.next(); | ||
iterator['return'](); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/return-method-called-with-zero-arguments', function (s2t) { | ||
var returnCalled = 0; | ||
var testIterator1 = { | ||
next: function () { | ||
return { done: false }; | ||
}, | ||
'return': function () { | ||
returnCalled += 1; | ||
s2t.equal(arguments.length, 0); | ||
return { done: true }; | ||
} | ||
}; | ||
var iterable = {}; | ||
iterable[Symbol.iterator] = function () { | ||
return testIterator1; | ||
}; | ||
var iterator; | ||
// Call with zero arguments. | ||
iterator = concat(iterable); | ||
iterator.next(); | ||
s2t.equal(returnCalled, 0); | ||
iterator['return'](); | ||
s2t.equal(returnCalled, 1); | ||
// Call with one argument. | ||
iterator = concat(iterable); | ||
iterator.next(); | ||
s2t.equal(returnCalled, 1); | ||
iterator['return'](1); | ||
s2t.equal(returnCalled, 2); | ||
// Call with two arguments. | ||
iterator = concat(iterable); | ||
iterator.next(); | ||
s2t.equal(returnCalled, 2); | ||
iterator['return'](1, 2); | ||
s2t.equal(returnCalled, 3); | ||
s2t.end(); | ||
}); | ||
st.test('test262: test/built-ins/Iterator/concat/throws-typeerror-when-generator-is-running-next', function (s2t) { | ||
var enterCount = 0; | ||
var iterator; | ||
var testIterator1 = { | ||
next: function () { | ||
enterCount += 1; | ||
iterator.next(); | ||
return { done: false }; | ||
} | ||
}; | ||
var iterable = {}; | ||
iterable[Symbol.iterator] = function () { | ||
return testIterator1; | ||
}; | ||
iterator = concat(iterable); | ||
s2t.equal(enterCount, 0); | ||
s2t['throws'](function () { iterator.next(); }, TypeError); | ||
s2t.equal(enterCount, 1); | ||
s2t.end(); | ||
}); | ||
st.end(); | ||
@@ -126,2 +570,4 @@ }); | ||
t.equal(Iterator.concat.length, 0, 'Iterator.concat has length 0'); | ||
module.exports.tests(callBind(Iterator.concat, Iterator), 'Iterator.concat', t); | ||
@@ -128,0 +574,0 @@ |
@@ -44,9 +44,11 @@ 'use strict'; | ||
forEach(v.nonFunctions, function (nonFunction) { | ||
var badIterable = {}; | ||
badIterable[Symbol.iterator] = nonFunction; | ||
st['throws']( | ||
function () { zip([[], badIterable, []]).next(); }, | ||
TypeError, | ||
debug(badIterable) + ' is not a function' | ||
); | ||
if (nonFunction != null) { | ||
var badIterable = {}; | ||
badIterable[Symbol.iterator] = nonFunction; | ||
st['throws']( | ||
function () { zip([[], badIterable, []]).next(); }, | ||
TypeError, | ||
debug(badIterable) + ' is not a function' | ||
); | ||
} | ||
}); | ||
@@ -53,0 +55,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
207946
137
4852
111
16
+ Addedcall-bound@^1.0.3
Updatedcall-bind@^1.0.8
Updatedes-abstract@^1.23.6
Updatedget-intrinsic@^1.2.6
Updatedgopd@^1.2.0
Updatedhas-proto@^1.2.0
Updatedhas-symbols@^1.1.0
Updatedinternal-slot@^1.1.0
Updatediterator.prototype@^1.1.4
Updatedsafe-array-concat@^1.1.3