From f17389a78bd8c0cedfc2c200f7f98b77eabc0922 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Thu, 20 Oct 2022 12:57:38 +0700 Subject: [PATCH] add counter argument to async iterator helpers https://github.com/tc39/proposal-iterator-helpers/pull/211 --- .../internals/async-iterator-create-proxy.js | 1 + .../core-js/internals/async-iterator-iteration.js | 14 +++++++------- .../modules/esnext.async-iterator.filter.js | 2 +- .../modules/esnext.async-iterator.flat-map.js | 2 +- .../modules/esnext.async-iterator.indexed.js | 1 + .../core-js/modules/esnext.async-iterator.map.js | 2 +- .../modules/esnext.async-iterator.reduce.js | 4 +++- tests/pure/esnext.async-iterator.every.js | 7 ++++--- tests/pure/esnext.async-iterator.filter.js | 7 ++++--- tests/pure/esnext.async-iterator.find.js | 7 ++++--- tests/pure/esnext.async-iterator.flat-map.js | 7 ++++--- tests/pure/esnext.async-iterator.for-each.js | 7 ++++--- tests/pure/esnext.async-iterator.map.js | 7 ++++--- tests/pure/esnext.async-iterator.reduce.js | 7 ++++--- tests/pure/esnext.async-iterator.some.js | 7 ++++--- tests/tests/esnext.async-iterator.every.js | 7 ++++--- tests/tests/esnext.async-iterator.filter.js | 7 ++++--- tests/tests/esnext.async-iterator.find.js | 7 ++++--- tests/tests/esnext.async-iterator.flat-map.js | 7 ++++--- tests/tests/esnext.async-iterator.for-each.js | 7 ++++--- tests/tests/esnext.async-iterator.map.js | 7 ++++--- tests/tests/esnext.async-iterator.reduce.js | 7 ++++--- tests/tests/esnext.async-iterator.some.js | 7 ++++--- 23 files changed, 79 insertions(+), 59 deletions(-) diff --git a/packages/core-js/internals/async-iterator-create-proxy.js b/packages/core-js/internals/async-iterator-create-proxy.js index 759b00405489..f7c34275bca9 100644 --- a/packages/core-js/internals/async-iterator-create-proxy.js +++ b/packages/core-js/internals/async-iterator-create-proxy.js @@ -125,6 +125,7 @@ module.exports = function (nextHandler, IS_ITERATOR) { } else state = record; state.type = ASYNC_ITERATOR_PROXY; state.nextHandler = nextHandler; + state.counter = 0; state.done = false; state.awaiting = null; setInternalState(this, state); diff --git a/packages/core-js/internals/async-iterator-iteration.js b/packages/core-js/internals/async-iterator-iteration.js index 081369db7400..ef4c21916289 100644 --- a/packages/core-js/internals/async-iterator-iteration.js +++ b/packages/core-js/internals/async-iterator-iteration.js @@ -19,7 +19,7 @@ var createMethod = function (TYPE) { var Promise = getBuiltIn('Promise'); var iterator = record.iterator; var next = record.next; - var index = 0; + var counter = 0; var MAPPING = fn !== undefined; if (MAPPING || !IS_TO_ARRAY) aCallable(fn); @@ -30,28 +30,28 @@ var createMethod = function (TYPE) { var loop = function () { try { - if (IS_TO_ARRAY && MAPPING) try { - doesNotExceedSafeInteger(index); + if (MAPPING) try { + doesNotExceedSafeInteger(counter); } catch (error5) { ifAbruptCloseAsyncIterator(error5); } Promise.resolve(anObject(call(next, iterator))).then(function (step) { try { if (anObject(step).done) { if (IS_TO_ARRAY) { - target.length = index; + target.length = counter; resolve(target); } else resolve(IS_SOME ? false : IS_EVERY || undefined); } else { var value = step.value; try { if (MAPPING) { - Promise.resolve(IS_TO_ARRAY ? fn(value, index) : fn(value)).then(function (result) { + Promise.resolve(fn(value, counter)).then(function (result) { if (IS_FOR_EACH) { loop(); } else if (IS_EVERY) { result ? loop() : closeAsyncIteration(iterator, resolve, false, reject); } else if (IS_TO_ARRAY) { try { - target[index++] = result; + target[counter++] = result; loop(); } catch (error4) { ifAbruptCloseAsyncIterator(error4); } } else { @@ -59,7 +59,7 @@ var createMethod = function (TYPE) { } }, ifAbruptCloseAsyncIterator); } else { - target[index++] = value; + target[counter++] = value; loop(); } } catch (error3) { ifAbruptCloseAsyncIterator(error3); } diff --git a/packages/core-js/modules/esnext.async-iterator.filter.js b/packages/core-js/modules/esnext.async-iterator.filter.js index b696e7dfd283..49c9700ee7fb 100644 --- a/packages/core-js/modules/esnext.async-iterator.filter.js +++ b/packages/core-js/modules/esnext.async-iterator.filter.js @@ -34,7 +34,7 @@ var AsyncIteratorProxy = createAsyncIteratorProxy(function (Promise) { } else { var value = step.value; try { - Promise.resolve(filterer(value)).then(function (selected) { + Promise.resolve(filterer(value, state.counter++)).then(function (selected) { selected ? resolve(createIterResultObject(value, false)) : loop(); }, ifAbruptCloseAsyncIterator); } catch (error3) { ifAbruptCloseAsyncIterator(error3); } diff --git a/packages/core-js/modules/esnext.async-iterator.flat-map.js b/packages/core-js/modules/esnext.async-iterator.flat-map.js index 8183283cc6e3..7e12ba7b4069 100644 --- a/packages/core-js/modules/esnext.async-iterator.flat-map.js +++ b/packages/core-js/modules/esnext.async-iterator.flat-map.js @@ -36,7 +36,7 @@ var AsyncIteratorProxy = createAsyncIteratorProxy(function (Promise) { } else { var value = step.value; try { - Promise.resolve(mapper(value)).then(function (mapped) { + Promise.resolve(mapper(value, state.counter++)).then(function (mapped) { try { state.innerIterator = innerIterator = getAsyncIterator(mapped); state.innerNext = aCallable(innerIterator.next); diff --git a/packages/core-js/modules/esnext.async-iterator.indexed.js b/packages/core-js/modules/esnext.async-iterator.indexed.js index 5be9d38bcea5..43965e1781b1 100644 --- a/packages/core-js/modules/esnext.async-iterator.indexed.js +++ b/packages/core-js/modules/esnext.async-iterator.indexed.js @@ -1,3 +1,4 @@ +// TODO: Remove from `core-js@4` // https://github.com/tc39/proposal-iterator-helpers var $ = require('../internals/export'); var indexed = require('../internals/async-iterator-indexed'); diff --git a/packages/core-js/modules/esnext.async-iterator.map.js b/packages/core-js/modules/esnext.async-iterator.map.js index 0f49efdf24b4..f6b6cae94362 100644 --- a/packages/core-js/modules/esnext.async-iterator.map.js +++ b/packages/core-js/modules/esnext.async-iterator.map.js @@ -32,7 +32,7 @@ var AsyncIteratorProxy = createAsyncIteratorProxy(function (Promise) { } else { var value = step.value; try { - Promise.resolve(mapper(value)).then(function (mapped) { + Promise.resolve(mapper(value, state.counter++)).then(function (mapped) { resolve(createIterResultObject(mapped, false)); }, ifAbruptCloseAsyncIterator); } catch (error2) { ifAbruptCloseAsyncIterator(error2); } diff --git a/packages/core-js/modules/esnext.async-iterator.reduce.js b/packages/core-js/modules/esnext.async-iterator.reduce.js index 528498359c92..02f819ebd86c 100644 --- a/packages/core-js/modules/esnext.async-iterator.reduce.js +++ b/packages/core-js/modules/esnext.async-iterator.reduce.js @@ -18,6 +18,7 @@ $({ target: 'AsyncIterator', proto: true, real: true, forced: true }, { var next = record.next; var noInitial = arguments.length < 2; var accumulator = noInitial ? undefined : arguments[1]; + var counter = 0; aCallable(reducer); return new Promise(function (resolve, reject) { @@ -38,12 +39,13 @@ $({ target: 'AsyncIterator', proto: true, real: true, forced: true }, { accumulator = value; loop(); } else try { - Promise.resolve(reducer(accumulator, value)).then(function (result) { + Promise.resolve(reducer(accumulator, value, counter)).then(function (result) { accumulator = result; loop(); }, ifAbruptCloseAsyncIterator); } catch (error3) { ifAbruptCloseAsyncIterator(error3); } } + counter++; } catch (error2) { reject(error2); } }, reject); } catch (error) { reject(error); } diff --git a/tests/pure/esnext.async-iterator.every.js b/tests/pure/esnext.async-iterator.every.js index f008d1d9630e..c4a2a9ccf538 100644 --- a/tests/pure/esnext.async-iterator.every.js +++ b/tests/pure/esnext.async-iterator.every.js @@ -4,7 +4,7 @@ import { STRICT_THIS } from '../helpers/constants'; import AsyncIterator from 'core-js-pure/full/async-iterator'; QUnit.test('AsyncIterator#every', assert => { - assert.expect(16); + assert.expect(17); const async = assert.async(); const { every } = AsyncIterator.prototype; @@ -17,10 +17,11 @@ QUnit.test('AsyncIterator#every', assert => { return every.call(createIterator([1, 2, 3]), it => it === 2); }).then(result => { assert.false(result, 'basic functionality, -'); - return every.call(createIterator([1]), function (arg) { + return every.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); }); }).then(() => { return every.call(createIterator([1]), () => { throw 42; }); diff --git a/tests/pure/esnext.async-iterator.filter.js b/tests/pure/esnext.async-iterator.filter.js index 3065c38e7469..3fc952733fa5 100644 --- a/tests/pure/esnext.async-iterator.filter.js +++ b/tests/pure/esnext.async-iterator.filter.js @@ -4,7 +4,7 @@ import { STRICT_THIS } from '../helpers/constants'; import AsyncIterator from 'core-js-pure/full/async-iterator'; QUnit.test('AsyncIterator#filter', assert => { - assert.expect(15); + assert.expect(16); const async = assert.async(); const { filter } = AsyncIterator.prototype; @@ -14,10 +14,11 @@ QUnit.test('AsyncIterator#filter', assert => { filter.call(createIterator([1, 2, 3]), it => it % 2).toArray().then(it => { assert.arrayEqual(it, [1, 3], 'basic functionality'); - return filter.call(createIterator([1]), function (arg) { + return filter.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); }).toArray(); }).then(() => { return filter.call(createIterator([1]), () => { throw 42; }).toArray(); diff --git a/tests/pure/esnext.async-iterator.find.js b/tests/pure/esnext.async-iterator.find.js index a969dd9f3e3c..83d6e78839d8 100644 --- a/tests/pure/esnext.async-iterator.find.js +++ b/tests/pure/esnext.async-iterator.find.js @@ -4,7 +4,7 @@ import { STRICT_THIS } from '../helpers/constants'; import AsyncIterator from 'core-js-pure/full/async-iterator'; QUnit.test('AsyncIterator#find', assert => { - assert.expect(16); + assert.expect(17); const async = assert.async(); const { find } = AsyncIterator.prototype; @@ -17,10 +17,11 @@ QUnit.test('AsyncIterator#find', assert => { return find.call(createIterator([1, 2, 3]), it => it === 4); }).then(result => { assert.same(result, undefined, 'basic functionality, -'); - return find.call(createIterator([1]), function (arg) { + return find.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); }); }).then(() => { return find.call(createIterator([1]), () => { throw 42; }); diff --git a/tests/pure/esnext.async-iterator.flat-map.js b/tests/pure/esnext.async-iterator.flat-map.js index 29277f8bcb1a..d870c80d365c 100644 --- a/tests/pure/esnext.async-iterator.flat-map.js +++ b/tests/pure/esnext.async-iterator.flat-map.js @@ -4,7 +4,7 @@ import { STRICT_THIS } from '../helpers/constants'; import AsyncIterator from 'core-js-pure/full/async-iterator'; QUnit.test('AsyncIterator#flatMap', assert => { - assert.expect(15); + assert.expect(16); const async = assert.async(); const { flatMap } = AsyncIterator.prototype; @@ -14,10 +14,11 @@ QUnit.test('AsyncIterator#flatMap', assert => { flatMap.call(createIterator([1, [], 2, createIterable([3, 4]), [5, 6], 'ab']), it => typeof it == 'number' ? [-it] : it).toArray().then(it => { assert.arrayEqual(it, [-1, -2, 3, 4, 5, 6, 'a', 'b'], 'basic functionality'); - return flatMap.call(createIterator([1]), function (arg) { + return flatMap.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); return [arg]; }).toArray(); }).then(() => { diff --git a/tests/pure/esnext.async-iterator.for-each.js b/tests/pure/esnext.async-iterator.for-each.js index 911bd3acaa65..dd65cc7cd8b4 100644 --- a/tests/pure/esnext.async-iterator.for-each.js +++ b/tests/pure/esnext.async-iterator.for-each.js @@ -4,7 +4,7 @@ import { STRICT_THIS } from '../helpers/constants'; import AsyncIterator from 'core-js-pure/full/async-iterator'; QUnit.test('AsyncIterator#forEach', assert => { - assert.expect(15); + assert.expect(16); const async = assert.async(); const { forEach } = AsyncIterator.prototype; @@ -16,10 +16,11 @@ QUnit.test('AsyncIterator#forEach', assert => { forEach.call(createIterator([1, 2, 3]), it => array.push(it)).then(() => { assert.arrayEqual(array, [1, 2, 3], 'basic functionality'); - return forEach.call(createIterator([1]), function (arg) { + return forEach.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); }); }).then(() => { return forEach.call(createIterator([1]), () => { throw 42; }); diff --git a/tests/pure/esnext.async-iterator.map.js b/tests/pure/esnext.async-iterator.map.js index cca9ff38e66f..481b1297c06e 100644 --- a/tests/pure/esnext.async-iterator.map.js +++ b/tests/pure/esnext.async-iterator.map.js @@ -4,7 +4,7 @@ import { STRICT_THIS } from '../helpers/constants'; import AsyncIterator from 'core-js-pure/full/async-iterator'; QUnit.test('AsyncIterator#map', assert => { - assert.expect(15); + assert.expect(16); const async = assert.async(); const { map } = AsyncIterator.prototype; @@ -14,10 +14,11 @@ QUnit.test('AsyncIterator#map', assert => { map.call(createIterator([1, 2, 3]), it => it ** 2).toArray().then(it => { assert.arrayEqual(it, [1, 4, 9], 'basic functionality'); - return map.call(createIterator([1]), function (arg) { + return map.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); }).toArray(); }).then(() => { return map.call(createIterator([1]), () => { throw 42; }).toArray(); diff --git a/tests/pure/esnext.async-iterator.reduce.js b/tests/pure/esnext.async-iterator.reduce.js index aae18f234ee2..5e7653d16747 100644 --- a/tests/pure/esnext.async-iterator.reduce.js +++ b/tests/pure/esnext.async-iterator.reduce.js @@ -4,7 +4,7 @@ import { STRICT_THIS } from '../helpers/constants'; import AsyncIterator from 'core-js-pure/full/async-iterator'; QUnit.test('AsyncIterator#reduce', assert => { - assert.expect(18); + assert.expect(19); const async = assert.async(); const { reduce } = AsyncIterator.prototype; @@ -14,11 +14,12 @@ QUnit.test('AsyncIterator#reduce', assert => { reduce.call(createIterator([1, 2, 3]), (a, b) => a + b, 1).then(it => { assert.same(it, 7, 'basic functionality, initial'); - return reduce.call(createIterator([2]), function (a, b) { + return reduce.call(createIterator([2]), function (a, b, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 2, 'arguments length'); + assert.same(arguments.length, 3, 'arguments length'); assert.same(a, 1, 'argument 1'); assert.same(b, 2, 'argument 2'); + assert.same(counter, 0, 'counter'); }, 1); }).then(() => { return reduce.call(createIterator([1, 2, 3]), (a, b) => a + b); diff --git a/tests/pure/esnext.async-iterator.some.js b/tests/pure/esnext.async-iterator.some.js index 8ce41e29bb6e..9b7e973d2894 100644 --- a/tests/pure/esnext.async-iterator.some.js +++ b/tests/pure/esnext.async-iterator.some.js @@ -4,7 +4,7 @@ import { STRICT_THIS } from '../helpers/constants'; import AsyncIterator from 'core-js-pure/full/async-iterator'; QUnit.test('AsyncIterator#some', assert => { - assert.expect(16); + assert.expect(17); const async = assert.async(); const { some } = AsyncIterator.prototype; @@ -17,10 +17,11 @@ QUnit.test('AsyncIterator#some', assert => { return some.call(createIterator([1, 2, 3]), it => it === 4); }).then(result => { assert.false(result, 'basic functionality, -'); - return some.call(createIterator([1]), function (arg) { + return some.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); }); }).then(() => { return some.call(createIterator([1]), () => { throw 42; }); diff --git a/tests/tests/esnext.async-iterator.every.js b/tests/tests/esnext.async-iterator.every.js index bc4466c2d9cc..243ac7eaf3be 100644 --- a/tests/tests/esnext.async-iterator.every.js +++ b/tests/tests/esnext.async-iterator.every.js @@ -2,7 +2,7 @@ import { createIterator } from '../helpers/helpers'; import { STRICT_THIS } from '../helpers/constants'; QUnit.test('AsyncIterator#every', assert => { - assert.expect(18); + assert.expect(19); const async = assert.async(); const { every } = AsyncIterator.prototype; @@ -17,10 +17,11 @@ QUnit.test('AsyncIterator#every', assert => { return every.call(createIterator([1, 2, 3]), it => it === 2); }).then(result => { assert.false(result, 'basic functionality, -'); - return every.call(createIterator([1]), function (arg) { + return every.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); }); }).then(() => { return every.call(createIterator([1]), () => { throw 42; }); diff --git a/tests/tests/esnext.async-iterator.filter.js b/tests/tests/esnext.async-iterator.filter.js index 1f5c02bff650..82facc15dc3d 100644 --- a/tests/tests/esnext.async-iterator.filter.js +++ b/tests/tests/esnext.async-iterator.filter.js @@ -2,7 +2,7 @@ import { createIterator } from '../helpers/helpers'; import { STRICT_THIS } from '../helpers/constants'; QUnit.test('AsyncIterator#filter', assert => { - assert.expect(17); + assert.expect(18); const async = assert.async(); const { filter } = AsyncIterator.prototype; @@ -14,10 +14,11 @@ QUnit.test('AsyncIterator#filter', assert => { filter.call(createIterator([1, 2, 3]), it => it % 2).toArray().then(it => { assert.arrayEqual(it, [1, 3], 'basic functionality'); - return filter.call(createIterator([1]), function (arg) { + return filter.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); }).toArray(); }).then(() => { return filter.call(createIterator([1]), () => { throw 42; }).toArray(); diff --git a/tests/tests/esnext.async-iterator.find.js b/tests/tests/esnext.async-iterator.find.js index 2c745ac2e383..e49a83d66830 100644 --- a/tests/tests/esnext.async-iterator.find.js +++ b/tests/tests/esnext.async-iterator.find.js @@ -2,7 +2,7 @@ import { createIterator } from '../helpers/helpers'; import { STRICT_THIS } from '../helpers/constants'; QUnit.test('AsyncIterator#find', assert => { - assert.expect(18); + assert.expect(19); const async = assert.async(); const { find } = AsyncIterator.prototype; @@ -17,10 +17,11 @@ QUnit.test('AsyncIterator#find', assert => { return find.call(createIterator([1, 2, 3]), it => it === 4); }).then(result => { assert.same(result, undefined, 'basic functionality, -'); - return find.call(createIterator([1]), function (arg) { + return find.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); }); }).then(() => { return find.call(createIterator([1]), () => { throw 42; }); diff --git a/tests/tests/esnext.async-iterator.flat-map.js b/tests/tests/esnext.async-iterator.flat-map.js index f0c84df2f41e..f287aec5b88c 100644 --- a/tests/tests/esnext.async-iterator.flat-map.js +++ b/tests/tests/esnext.async-iterator.flat-map.js @@ -2,7 +2,7 @@ import { createIterator, createIterable } from '../helpers/helpers'; import { STRICT_THIS } from '../helpers/constants'; QUnit.test('AsyncIterator#flatMap', assert => { - assert.expect(17); + assert.expect(18); const async = assert.async(); const { flatMap } = AsyncIterator.prototype; @@ -14,10 +14,11 @@ QUnit.test('AsyncIterator#flatMap', assert => { flatMap.call(createIterator([1, [], 2, createIterable([3, 4]), [5, 6], 'ab']), it => typeof it == 'number' ? [-it] : it).toArray().then(it => { assert.arrayEqual(it, [-1, -2, 3, 4, 5, 6, 'a', 'b'], 'basic functionality'); - return flatMap.call(createIterator([1]), function (arg) { + return flatMap.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); return [arg]; }).toArray(); }).then(() => { diff --git a/tests/tests/esnext.async-iterator.for-each.js b/tests/tests/esnext.async-iterator.for-each.js index db4776e171dc..4a08ba3347e8 100644 --- a/tests/tests/esnext.async-iterator.for-each.js +++ b/tests/tests/esnext.async-iterator.for-each.js @@ -2,7 +2,7 @@ import { createIterator } from '../helpers/helpers'; import { STRICT_THIS } from '../helpers/constants'; QUnit.test('AsyncIterator#forEach', assert => { - assert.expect(17); + assert.expect(18); const async = assert.async(); const { forEach } = AsyncIterator.prototype; @@ -16,10 +16,11 @@ QUnit.test('AsyncIterator#forEach', assert => { forEach.call(createIterator([1, 2, 3]), it => array.push(it)).then(() => { assert.arrayEqual(array, [1, 2, 3], 'basic functionality'); - return forEach.call(createIterator([1]), function (arg) { + return forEach.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); }); }).then(() => { return forEach.call(createIterator([1]), () => { throw 42; }); diff --git a/tests/tests/esnext.async-iterator.map.js b/tests/tests/esnext.async-iterator.map.js index 6e13fab0ff75..e8befba5db51 100644 --- a/tests/tests/esnext.async-iterator.map.js +++ b/tests/tests/esnext.async-iterator.map.js @@ -2,7 +2,7 @@ import { createIterator } from '../helpers/helpers'; import { STRICT_THIS } from '../helpers/constants'; QUnit.test('AsyncIterator#map', assert => { - assert.expect(17); + assert.expect(18); const async = assert.async(); const { map } = AsyncIterator.prototype; @@ -14,10 +14,11 @@ QUnit.test('AsyncIterator#map', assert => { map.call(createIterator([1, 2, 3]), it => it ** 2).toArray().then(it => { assert.arrayEqual(it, [1, 4, 9], 'basic functionality'); - return map.call(createIterator([1]), function (arg) { + return map.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); }).toArray(); }).then(() => { return map.call(createIterator([1]), () => { throw 42; }).toArray(); diff --git a/tests/tests/esnext.async-iterator.reduce.js b/tests/tests/esnext.async-iterator.reduce.js index 9fbab8302f53..301d6219653f 100644 --- a/tests/tests/esnext.async-iterator.reduce.js +++ b/tests/tests/esnext.async-iterator.reduce.js @@ -2,7 +2,7 @@ import { createIterator } from '../helpers/helpers'; import { STRICT_THIS } from '../helpers/constants'; QUnit.test('AsyncIterator#reduce', assert => { - assert.expect(20); + assert.expect(21); const async = assert.async(); const { reduce } = AsyncIterator.prototype; @@ -14,11 +14,12 @@ QUnit.test('AsyncIterator#reduce', assert => { reduce.call(createIterator([1, 2, 3]), (a, b) => a + b, 1).then(it => { assert.same(it, 7, 'basic functionality, initial'); - return reduce.call(createIterator([2]), function (a, b) { + return reduce.call(createIterator([2]), function (a, b, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 2, 'arguments length'); + assert.same(arguments.length, 3, 'arguments length'); assert.same(a, 1, 'argument 1'); assert.same(b, 2, 'argument 2'); + assert.same(counter, 0, 'counter'); }, 1); }).then(() => { return reduce.call(createIterator([1, 2, 3]), (a, b) => a + b); diff --git a/tests/tests/esnext.async-iterator.some.js b/tests/tests/esnext.async-iterator.some.js index 5eda1ebf277c..ac6d004bd3bd 100644 --- a/tests/tests/esnext.async-iterator.some.js +++ b/tests/tests/esnext.async-iterator.some.js @@ -2,7 +2,7 @@ import { createIterator } from '../helpers/helpers'; import { STRICT_THIS } from '../helpers/constants'; QUnit.test('AsyncIterator#some', assert => { - assert.expect(18); + assert.expect(19); const async = assert.async(); const { some } = AsyncIterator.prototype; @@ -17,10 +17,11 @@ QUnit.test('AsyncIterator#some', assert => { return some.call(createIterator([1, 2, 3]), it => it === 4); }).then(result => { assert.false(result, 'basic functionality, -'); - return some.call(createIterator([1]), function (arg) { + return some.call(createIterator([1]), function (arg, counter) { assert.same(this, STRICT_THIS, 'this'); - assert.same(arguments.length, 1, 'arguments length'); + assert.same(arguments.length, 2, 'arguments length'); assert.same(arg, 1, 'argument'); + assert.same(counter, 0, 'counter'); }); }).then(() => { return some.call(createIterator([1]), () => { throw 42; });