Skip to content

Commit 1c5476d

Browse files
committed
AsyncIterator, pt 3
1 parent 896d93c commit 1c5476d

53 files changed

Lines changed: 1117 additions & 509 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

test/built-ins/AsyncIterator/prototype/asIndexedPairs/abrupt-iterator-get-next.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,51 @@ description: >
77
info: |
88
%AsyncIterator.prototype%.asIndexedPairs ( )
99
10-
%AsyncIterator.prototype%.asIndexedPairs is a built-in async generator function which, when called, performs the following prelude steps:
11-
12-
Let iterated be ? GetIteratorDirect(this value).
13-
14-
The body of %AsyncIterator.prototype%.asIndexedPairs is composed of the following steps:
15-
10+
Let iterated be ? GetIteratorDirect(this value).
11+
Let closure be a new Abstract Closure with no parameters that captures iterated and performs the following steps when called:
1612
Let index be 0.
1713
Let lastValue be undefined.
1814
Repeat,
1915
Let next be ? Await(? IteratorNext(iterated, lastValue)).
2016
...
2117
18+
IteratorNext ( iteratorRecord [ , value ] )
19+
20+
If value is not present, then
21+
Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]).
22+
Else,
23+
Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « value »).
24+
If Type(result) is not Object, throw a TypeError exception.
25+
Return result.
26+
27+
2228
includes: [iterators.js]
2329
features: [async-iteration, iterator-helpers]
2430
flags: [async]
2531
---*/
32+
let nextGets = 0;
2633
class Test262AsyncIteratorAbrupt extends Test262AsyncIterator {
2734
get next() {
35+
nextGets++;
2836
throw new Test262Error();
2937
}
3038
}
3139

3240
(async () => {
33-
let count = 0;
34-
let iterator = new Test262AsyncIteratorAbrupt([0, 1, 2, 3]);
35-
assert.sameValue(iterator.nextCalls, 0, 'The value of iterator.nextCalls is 0');
41+
let tryCount = 0;
42+
let catchCount = 0;
43+
let iterator = new Test262AsyncIteratorAbrupt([1, 2]);
44+
assert.sameValue(nextGets, 0, 'The value of `nextGets` is 0');
3645

3746
try {
47+
tryCount++;
3848
iterator.asIndexedPairs();
3949
} catch (e) {
40-
count++;
50+
catchCount++;
4151
assert.sameValue(e instanceof Test262Error, true, 'The result of evaluating `(e instanceof Test262Error)` is true');
4252
}
4353

44-
assert.sameValue(count, 1, 'The value of `count` is 1');
45-
assert.sameValue(iterator.nextCalls, 0, 'The value of iterator.nextCalls is 0');
46-
assert.sameValue(iterator.iterable.length, 4, 'The value of iterator.iterable.length is 4');
54+
assert.sameValue(tryCount, 1, 'The value of `tryCount` is 1');
55+
assert.sameValue(catchCount, 1, 'The value of `catchCount` is 1');
56+
assert.sameValue(nextGets, 1, 'The value of `nextGets` is 1');
4757
})().then($DONE, $DONE);

test/built-ins/AsyncIterator/prototype/asIndexedPairs/abrupt-iterator-get-return.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ description: >
77
info: |
88
%AsyncIterator.prototype%.asIndexedPairs ( )
99
10-
%AsyncIterator.prototype%.asIndexedPairs is a built-in async generator function which, when called, performs the following prelude steps:
11-
12-
Let iterated be ? GetIteratorDirect(this value).
13-
14-
The body of %AsyncIterator.prototype%.asIndexedPairs is composed of the following steps:
15-
10+
Let iterated be ? GetIteratorDirect(this value).
11+
Let closure be a new Abstract Closure with no parameters that captures iterated and performs the following steps when called:
1612
Let index be 0.
1713
Let lastValue be undefined.
1814
Repeat,
@@ -23,14 +19,15 @@ info: |
2319
Set index to index + 1.
2420
Set lastValue to Yield(pair).
2521
IfAbruptCloseAsyncIterator(iterated, lastValue).
22+
...
2623
2724
features: [async-iteration, iterator-helpers]
2825
flags: [async]
2926
---*/
30-
let genCount = 0;
27+
let yieldCount = 0;
3128

3229
async function* g() {
33-
genCount++;
30+
yieldCount++;
3431
}
3532

3633
(async () => {
@@ -56,7 +53,7 @@ async function* g() {
5653
assert.sameValue(e instanceof Test262Error, true, 'The result of evaluating `(e instanceof Test262Error)` is true');
5754
}
5855

59-
assert.sameValue(genCount, 1, 'The value of `genCount` is 1');
56+
assert.sameValue(yieldCount, 1, 'The value of `yieldCount` is 1');
6057
assert.sameValue(tryCount, 1, 'The value of `tryCount` is 1');
6158
assert.sameValue(catchCount, 1, 'The value of `catchCount` is 1');
6259
assert.sameValue(returnCount, 1, 'The value of `returnCount` is 1');

test/built-ins/AsyncIterator/prototype/asIndexedPairs/abrupt-iterator-next-done.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,29 @@ description: >
77
info: |
88
%AsyncIterator.prototype%.asIndexedPairs ( )
99
10-
%AsyncIterator.prototype%.asIndexedPairs is a built-in async generator function which, when called, performs the following prelude steps:
11-
12-
Let iterated be ? GetIteratorDirect(this value).
13-
14-
The body of %AsyncIterator.prototype%.asIndexedPairs is composed of the following steps:
15-
10+
Let iterated be ? GetIteratorDirect(this value).
11+
Let closure be a new Abstract Closure with no parameters that captures iterated and performs the following steps when called:
1612
Let index be 0.
1713
Let lastValue be undefined.
1814
Repeat,
1915
Let next be ? Await(? IteratorNext(iterated, lastValue)).
2016
If ? IteratorComplete(next) is true, return undefined.
2117
...
2218
19+
IteratorComplete ( iterResult )
20+
21+
Return ! ToBoolean(? Get(iterResult, "done")).
22+
2323
includes: [iterators.js]
2424
features: [async-iteration, iterator-helpers]
2525
flags: [async]
2626
---*/
2727
let doneCount = 0;
28+
let nextCalls = 0;
2829

2930
class Test262AsyncIteratorAbrupt extends Test262AsyncIterator {
3031
async next() {
31-
this.nextCalls++;
32+
nextCalls++;
3233

3334
return {
3435
get done() {
@@ -43,14 +44,12 @@ class Test262AsyncIteratorAbrupt extends Test262AsyncIterator {
4344

4445
(async () => {
4546
let count = 0;
46-
let iterator = new Test262AsyncIteratorAbrupt([0, 1, 2, 3]);
47-
assert.sameValue(iterator.nextCalls, 0, 'The value of iterator.nextCalls is 0');
48-
let indexedPairs = iterator.asIndexedPairs();
47+
let iterator = new Test262AsyncIteratorAbrupt([1, 2]).asIndexedPairs();
4948

5049
try {
5150
count++;
5251

53-
for await (const [i, v] of indexedPairs) {
52+
for await (const [i, v] of iterator) {
5453
$DONE('for await body must not be reachable');
5554
}
5655
} catch (e) {
@@ -59,6 +58,5 @@ class Test262AsyncIteratorAbrupt extends Test262AsyncIterator {
5958
}
6059

6160
assert.sameValue(doneCount, 1, 'The value of `doneCount` is 1');
62-
assert.sameValue(iterator.nextCalls, 1, 'The value of iterator.nextCalls is 1');
63-
assert.sameValue(iterator.iterable.length, 4, 'The value of iterator.iterable.length is 4');
61+
assert.sameValue(nextCalls, 1, 'The value of `nextCalls` is 1');
6462
})().then($DONE, $DONE);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (C) 2020 Rick Waldron. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
esid: sec-asynciteratorprototype.asindexedpairs
5+
description: >
6+
Returns abrupt when next accessor is abrupt.
7+
info: |
8+
%AsyncIterator.prototype%.asIndexedPairs ( )
9+
10+
Let iterated be ? GetIteratorDirect(this value).
11+
Let closure be a new Abstract Closure with no parameters that captures iterated and performs the following steps when called:
12+
Let index be 0.
13+
Let lastValue be undefined.
14+
Repeat,
15+
Let next be ? Await(? IteratorNext(iterated, lastValue)).
16+
...
17+
18+
IteratorNext ( iteratorRecord [ , value ] )
19+
20+
If value is not present, then
21+
Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]).
22+
Else,
23+
Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « value »).
24+
If Type(result) is not Object, throw a TypeError exception.
25+
Return result.
26+
27+
28+
includes: [iterators.js]
29+
features: [async-iteration, iterator-helpers]
30+
flags: [async]
31+
---*/
32+
let nextCalls = 0;
33+
class Test262AsyncIteratorAbrupt extends Test262AsyncIterator {
34+
async next() {
35+
nextCalls++;
36+
return null;
37+
}
38+
}
39+
40+
(async () => {
41+
let catchCount = 0;
42+
let iterator = (new Test262AsyncIteratorAbrupt([1, 2])
43+
).asIndexedPairs();
44+
45+
try {
46+
await iterator.next();
47+
} catch (e) {
48+
catchCount++;
49+
assert.sameValue(e instanceof TypeError, true, 'The result of evaluating `(e instanceof TypeError)` is true');
50+
}
51+
52+
assert.sameValue(catchCount, 1, 'The value of `catchCount` is 1');
53+
assert.sameValue(nextCalls, 1, 'The value of `nextCalls` is 1');
54+
})().then($DONE, $DONE);

test/built-ins/AsyncIterator/prototype/asIndexedPairs/abrupt-iterator-next-value.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ description: >
77
info: |
88
%AsyncIterator.prototype%.asIndexedPairs ( )
99
10-
%AsyncIterator.prototype%.asIndexedPairs is a built-in async generator function which, when called, performs the following prelude steps:
11-
12-
Let iterated be ? GetIteratorDirect(this value).
13-
14-
The body of %AsyncIterator.prototype%.asIndexedPairs is composed of the following steps:
15-
10+
Let iterated be ? GetIteratorDirect(this value).
11+
Let closure be a new Abstract Closure with no parameters that captures iterated and performs the following steps when called:
1612
Let index be 0.
1713
Let lastValue be undefined.
1814
Repeat,
@@ -21,15 +17,20 @@ info: |
2117
Let value be ? IteratorValue(next).
2218
...
2319
20+
IteratorValue ( iterResult )
21+
22+
Return ? Get(iterResult, "value").
23+
2424
includes: [iterators.js]
2525
features: [async-iteration, iterator-helpers]
2626
flags: [async]
2727
---*/
28+
let nextCalls = 0;
2829
let valueCount = 0;
2930

3031
class Test262AsyncIteratorAbrupt extends Test262AsyncIterator {
3132
async next() {
32-
this.nextCalls++;
33+
nextCalls++;
3334

3435
return {
3536
get value() {
@@ -42,8 +43,7 @@ class Test262AsyncIteratorAbrupt extends Test262AsyncIterator {
4243

4344
(async () => {
4445
let count = 0;
45-
let iterator = new Test262AsyncIteratorAbrupt([0, 1, 2, 3]);
46-
assert.sameValue(iterator.nextCalls, 0, 'The value of iterator.nextCalls is 0');
46+
let iterator = new Test262AsyncIteratorAbrupt([1, 2]);
4747
let indexedPairs = iterator.asIndexedPairs();
4848

4949
try {
@@ -57,7 +57,6 @@ class Test262AsyncIteratorAbrupt extends Test262AsyncIterator {
5757
assert.sameValue(e instanceof Test262Error, true, 'The result of evaluating `(e instanceof Test262Error)` is true');
5858
}
5959

60+
assert.sameValue(nextCalls, 1, 'The value of `nextCalls` is 1');
6061
assert.sameValue(valueCount, 1, 'The value of `valueCount` is 1');
61-
assert.sameValue(iterator.nextCalls, 1, 'The value of iterator.nextCalls is 1');
62-
assert.sameValue(iterator.iterable.length, 4, 'The value of iterator.iterable.length is 4');
6362
})().then($DONE, $DONE);

test/built-ins/AsyncIterator/prototype/asIndexedPairs/abrupt-iterator-next.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ description: >
77
info: |
88
%AsyncIterator.prototype%.asIndexedPairs ( )
99
10-
%AsyncIterator.prototype%.asIndexedPairs is a built-in async generator function which, when called, performs the following prelude steps:
11-
12-
Let iterated be ? GetIteratorDirect(this value).
13-
14-
The body of %AsyncIterator.prototype%.asIndexedPairs is composed of the following steps:
15-
10+
Let iterated be ? GetIteratorDirect(this value).
11+
Let closure be a new Abstract Closure with no parameters that captures iterated and performs the following steps when called:
1612
Let index be 0.
1713
Let lastValue be undefined.
1814
Repeat,
@@ -23,29 +19,33 @@ includes: [iterators.js]
2319
features: [async-iteration, iterator-helpers]
2420
flags: [async]
2521
---*/
22+
let nextCalls = 0;
23+
2624
class Test262AsyncIteratorAbrupt extends Test262AsyncIterator {
2725
async next() {
26+
nextCalls++;
2827
throw new Test262Error();
2928
}
3029
}
3130

3231
(async () => {
33-
let count = 0;
34-
let iterator = new Test262AsyncIteratorAbrupt([0, 1, 2, 3]);
35-
assert.sameValue(iterator.nextCalls, 0, 'The value of iterator.nextCalls is 0');
32+
let tryCount = 0;
33+
let catchCount = 0;
34+
let iterator = new Test262AsyncIteratorAbrupt([1, 2]);
3635
let indexedPairs = iterator.asIndexedPairs();
3736

3837
try {
39-
count++;
38+
tryCount++;
4039

4140
for await (const [i, v] of indexedPairs) {
4241
$DONE('for await body must not be reachable');
4342
}
4443
} catch (e) {
45-
count++;
44+
catchCount++;
4645
assert.sameValue(e instanceof Test262Error, true, 'The result of evaluating `(e instanceof Test262Error)` is true');
4746
}
4847

49-
assert.sameValue(iterator.nextCalls, 0, 'The value of iterator.nextCalls is 0');
50-
assert.sameValue(iterator.iterable.length, 4, 'The value of iterator.iterable.length is 4');
48+
assert.sameValue(tryCount, 1, 'The value of `tryCount` is 1');
49+
assert.sameValue(catchCount, 1, 'The value of `catchCount` is 1');
50+
assert.sameValue(nextCalls, 1, 'The value of `nextCalls` is 1');
5151
})().then($DONE, $DONE);

test/built-ins/AsyncIterator/prototype/asIndexedPairs/abrupt-iterator-return.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ description: >
77
info: |
88
%AsyncIterator.prototype%.asIndexedPairs ( )
99
10-
%AsyncIterator.prototype%.asIndexedPairs is a built-in async generator function which, when called, performs the following prelude steps:
11-
12-
Let iterated be ? GetIteratorDirect(this value).
13-
14-
The body of %AsyncIterator.prototype%.asIndexedPairs is composed of the following steps:
15-
10+
Let iterated be ? GetIteratorDirect(this value).
11+
Let closure be a new Abstract Closure with no parameters that captures iterated and performs the following steps when called:
1612
Let index be 0.
1713
Let lastValue be undefined.
1814
Repeat,
@@ -23,17 +19,17 @@ info: |
2319
Set index to index + 1.
2420
Set lastValue to Yield(pair).
2521
IfAbruptCloseAsyncIterator(iterated, lastValue).
26-
22+
...
2723
2824
features: [async-iteration, iterator-helpers]
2925
flags: [async]
3026
---*/
31-
let genCount = 0;
27+
let yieldCount = 0;
3228

3329
async function* g() {
34-
genCount++;
30+
yieldCount++;
3531
yield 1;
36-
genCount++;
32+
yieldCount++;
3733
throw new Test262Error();
3834
}
3935

@@ -54,7 +50,7 @@ async function* g() {
5450
assert.sameValue(e instanceof Test262Error, true, 'The result of evaluating `(e instanceof Test262Error)` is true');
5551
}
5652

57-
assert.sameValue(genCount, 2, 'The value of `genCount` is 2');
53+
assert.sameValue(yieldCount, 2, 'The value of `yieldCount` is 2');
5854
assert.sameValue(tryCount, 1, 'The value of `tryCount` is 1');
5955
assert.sameValue(catchCount, 1, 'The value of `catchCount` is 1');
6056
assert.sameValue(forAwaitCount, 1, 'The value of `forAwaitCount` is 1');

test/built-ins/AsyncIterator/prototype/asIndexedPairs/callable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ assert.throws(TypeError, () => {
1717

1818
assert.throws(TypeError, () => {
1919
new (new (class S extends AsyncIterator {})()).asIndexedPairs();
20-
}, '`let instance = new (class S extends AsyncIterator {})(); new instance.asIndexedPairs()` throws a TypeError exception');
20+
}, '`new (new (class S extends AsyncIterator {})()).asIndexedPairs()` throws a TypeError exception');

0 commit comments

Comments
 (0)