-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,369 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
test/built-ins/AsyncIterator/prototype/asIndexedPairs/abrupt-iterator-get-next.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (C) 2020 Rick Waldron. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-asynciteratorprototype.asindexedpairs | ||
description: > | ||
Returns abrupt when next accessor is abrupt. | ||
info: | | ||
%AsyncIterator.prototype%.asIndexedPairs ( ) | ||
%AsyncIterator.prototype%.asIndexedPairs is a built-in async generator function which, when called, performs the following prelude steps: | ||
Let iterated be ? GetIteratorDirect(this value). | ||
The body of %AsyncIterator.prototype%.asIndexedPairs is composed of the following steps: | ||
Let index be 0. | ||
Let lastValue be undefined. | ||
Repeat, | ||
Let next be ? Await(? IteratorNext(iterated, lastValue)). | ||
... | ||
includes: [iterators.js] | ||
features: [async-iteration, iterator-helpers] | ||
flags: [async] | ||
---*/ | ||
class Test262AsyncIteratorAbrupt extends Test262AsyncIterator { | ||
get next() { | ||
throw new Test262Error(); | ||
} | ||
} | ||
|
||
(async () => { | ||
let count = 0; | ||
let iterator = new Test262AsyncIteratorAbrupt([0, 1, 2, 3]); | ||
assert.sameValue(iterator.nextCalls, 0, 'The value of iterator.nextCalls is 0'); | ||
|
||
try { | ||
iterator.asIndexedPairs(); | ||
} catch (e) { | ||
count++; | ||
assert.sameValue(e instanceof Test262Error, true, 'The result of `(e instanceof Test262Error)` is true'); | ||
} | ||
|
||
assert.sameValue(count, 1, 'The value of `count` is 1'); | ||
assert.sameValue(iterator.nextCalls, 0, 'The value of iterator.nextCalls is 0'); | ||
assert.sameValue(iterator.iterable.length, 4, 'The value of iterator.iterable.length is 4'); | ||
})().then($DONE, $DONE); |
64 changes: 64 additions & 0 deletions
64
test/built-ins/AsyncIterator/prototype/asIndexedPairs/abrupt-iterator-get-return.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (C) 2020 Rick Waldron. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-asynciteratorprototype.asindexedpairs | ||
description: > | ||
Returns abrupt when return accessor is abrupt. | ||
info: | | ||
%AsyncIterator.prototype%.asIndexedPairs ( ) | ||
%AsyncIterator.prototype%.asIndexedPairs is a built-in async generator function which, when called, performs the following prelude steps: | ||
Let iterated be ? GetIteratorDirect(this value). | ||
The body of %AsyncIterator.prototype%.asIndexedPairs is composed of the following steps: | ||
Let index be 0. | ||
Let lastValue be undefined. | ||
Repeat, | ||
Let next be ? Await(? IteratorNext(iterated, lastValue)). | ||
If ? IteratorComplete(next) is true, return undefined. | ||
Let value be ? IteratorValue(next). | ||
Let pair be ! CreateArrayFromList(« index, value »). | ||
Set index to index + 1. | ||
Set lastValue to Yield(pair). | ||
IfAbruptCloseAsyncIterator(iterated, lastValue). | ||
features: [async-iteration, iterator-helpers] | ||
flags: [async] | ||
---*/ | ||
let genCount = 0; | ||
|
||
async function* g() { | ||
genCount++; | ||
} | ||
|
||
(async () => { | ||
let iterator = g().asIndexedPairs(); | ||
let proto = Object.getPrototypeOf(iterator); | ||
let tryCount = 0; | ||
let catchCount = 0; | ||
let returnCount = 0; | ||
|
||
Object.defineProperty(proto, 'return', { | ||
get() { | ||
returnCount++; | ||
throw new Test262Error(); | ||
} | ||
}); | ||
|
||
try { | ||
tryCount++; | ||
await iterator.next(); | ||
await iterator.return(); | ||
tryCount++; | ||
} catch (e) { | ||
catchCount++; | ||
assert.sameValue(e instanceof Test262Error, true, 'The result of `(e instanceof Test262Error)` is true'); | ||
} | ||
|
||
assert.sameValue(genCount, 1, 'The value of `genCount` is 1'); | ||
assert.sameValue(tryCount, 1, 'The value of `tryCount` is 1'); | ||
assert.sameValue(catchCount, 1, 'The value of `catchCount` is 1'); | ||
assert.sameValue(returnCount, 1, 'The value of `returnCount` is 1'); | ||
})().then($DONE, $DONE); |
64 changes: 64 additions & 0 deletions
64
test/built-ins/AsyncIterator/prototype/asIndexedPairs/abrupt-iterator-next-done.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (C) 2020 Rick Waldron. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-asynciteratorprototype.asindexedpairs | ||
description: > | ||
Returns abrupt when done accessor is abrupt. | ||
info: | | ||
%AsyncIterator.prototype%.asIndexedPairs ( ) | ||
%AsyncIterator.prototype%.asIndexedPairs is a built-in async generator function which, when called, performs the following prelude steps: | ||
Let iterated be ? GetIteratorDirect(this value). | ||
The body of %AsyncIterator.prototype%.asIndexedPairs is composed of the following steps: | ||
Let index be 0. | ||
Let lastValue be undefined. | ||
Repeat, | ||
Let next be ? Await(? IteratorNext(iterated, lastValue)). | ||
If ? IteratorComplete(next) is true, return undefined. | ||
... | ||
includes: [iterators.js] | ||
features: [async-iteration, iterator-helpers] | ||
flags: [async] | ||
---*/ | ||
let doneCount = 0; | ||
|
||
class Test262AsyncIteratorAbrupt extends Test262AsyncIterator { | ||
async next() { | ||
this.nextCalls++; | ||
|
||
return { | ||
get done() { | ||
doneCount++; | ||
throw new Test262Error(); | ||
}, | ||
|
||
value: 1 | ||
}; | ||
} | ||
} | ||
|
||
(async () => { | ||
let count = 0; | ||
let iterator = new Test262AsyncIteratorAbrupt([0, 1, 2, 3]); | ||
assert.sameValue(iterator.nextCalls, 0, 'The value of iterator.nextCalls is 0'); | ||
let indexedPairs = iterator.asIndexedPairs(); | ||
|
||
try { | ||
count++; | ||
|
||
for await (const [i, v] of indexedPairs) { | ||
$DONE('for await body must not be reachable'); | ||
} | ||
} catch (e) { | ||
count++; | ||
assert.sameValue(e instanceof Test262Error, true, 'The result of `(e instanceof Test262Error)` is true'); | ||
} | ||
|
||
assert.sameValue(doneCount, 1, 'The value of `doneCount` is 1'); | ||
assert.sameValue(iterator.nextCalls, 1, 'The value of iterator.nextCalls is 1'); | ||
assert.sameValue(iterator.iterable.length, 4, 'The value of iterator.iterable.length is 4'); | ||
})().then($DONE, $DONE); |
63 changes: 63 additions & 0 deletions
63
test/built-ins/AsyncIterator/prototype/asIndexedPairs/abrupt-iterator-next-value.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (C) 2020 Rick Waldron. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-asynciteratorprototype.asindexedpairs | ||
description: > | ||
Returns abrupt when value accessor is abrupt. | ||
info: | | ||
%AsyncIterator.prototype%.asIndexedPairs ( ) | ||
%AsyncIterator.prototype%.asIndexedPairs is a built-in async generator function which, when called, performs the following prelude steps: | ||
Let iterated be ? GetIteratorDirect(this value). | ||
The body of %AsyncIterator.prototype%.asIndexedPairs is composed of the following steps: | ||
Let index be 0. | ||
Let lastValue be undefined. | ||
Repeat, | ||
Let next be ? Await(? IteratorNext(iterated, lastValue)). | ||
If ? IteratorComplete(next) is true, return undefined. | ||
Let value be ? IteratorValue(next). | ||
... | ||
includes: [iterators.js] | ||
features: [async-iteration, iterator-helpers] | ||
flags: [async] | ||
---*/ | ||
let valueCount = 0; | ||
|
||
class Test262AsyncIteratorAbrupt extends Test262AsyncIterator { | ||
async next() { | ||
this.nextCalls++; | ||
|
||
return { | ||
get value() { | ||
valueCount++; | ||
throw new Test262Error(); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
(async () => { | ||
let count = 0; | ||
let iterator = new Test262AsyncIteratorAbrupt([0, 1, 2, 3]); | ||
assert.sameValue(iterator.nextCalls, 0, 'The value of iterator.nextCalls is 0'); | ||
let indexedPairs = iterator.asIndexedPairs(); | ||
|
||
try { | ||
count++; | ||
|
||
for await (const [i, v] of indexedPairs) { | ||
$DONE('for await body must not be reachable'); | ||
} | ||
} catch (e) { | ||
count++; | ||
assert.sameValue(e instanceof Test262Error, true, 'The result of `(e instanceof Test262Error)` is true'); | ||
} | ||
|
||
assert.sameValue(valueCount, 1, 'The value of `valueCount` is 1'); | ||
assert.sameValue(iterator.nextCalls, 1, 'The value of iterator.nextCalls is 1'); | ||
assert.sameValue(iterator.iterable.length, 4, 'The value of iterator.iterable.length is 4'); | ||
})().then($DONE, $DONE); |
51 changes: 51 additions & 0 deletions
51
test/built-ins/AsyncIterator/prototype/asIndexedPairs/abrupt-iterator-next.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (C) 2020 Rick Waldron. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-asynciteratorprototype.asindexedpairs | ||
description: > | ||
Returns abrupt when next call is abrupt. | ||
info: | | ||
%AsyncIterator.prototype%.asIndexedPairs ( ) | ||
%AsyncIterator.prototype%.asIndexedPairs is a built-in async generator function which, when called, performs the following prelude steps: | ||
Let iterated be ? GetIteratorDirect(this value). | ||
The body of %AsyncIterator.prototype%.asIndexedPairs is composed of the following steps: | ||
Let index be 0. | ||
Let lastValue be undefined. | ||
Repeat, | ||
Let next be ? Await(? IteratorNext(iterated, lastValue)). | ||
... | ||
includes: [iterators.js] | ||
features: [async-iteration, iterator-helpers] | ||
flags: [async] | ||
---*/ | ||
class Test262AsyncIteratorAbrupt extends Test262AsyncIterator { | ||
async next() { | ||
throw new Test262Error(); | ||
} | ||
} | ||
|
||
(async () => { | ||
let count = 0; | ||
let iterator = new Test262AsyncIteratorAbrupt([0, 1, 2, 3]); | ||
assert.sameValue(iterator.nextCalls, 0, 'The value of iterator.nextCalls is 0'); | ||
let indexedPairs = iterator.asIndexedPairs(); | ||
|
||
try { | ||
count++; | ||
|
||
for await (const [i, v] of indexedPairs) { | ||
$DONE('for await body must not be reachable'); | ||
} | ||
} catch (e) { | ||
count++; | ||
assert.sameValue(e instanceof Test262Error, true, 'The result of `(e instanceof Test262Error)` is true'); | ||
} | ||
|
||
assert.sameValue(iterator.nextCalls, 0, 'The value of iterator.nextCalls is 0'); | ||
assert.sameValue(iterator.iterable.length, 4, 'The value of iterator.iterable.length is 4'); | ||
})().then($DONE, $DONE); |
63 changes: 63 additions & 0 deletions
63
test/built-ins/AsyncIterator/prototype/asIndexedPairs/abrupt-iterator-return.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (C) 2020 Rick Waldron. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-asynciteratorprototype.asindexedpairs | ||
description: > | ||
Returns abrupt when return call is abrupt. | ||
info: | | ||
%AsyncIterator.prototype%.asIndexedPairs ( ) | ||
%AsyncIterator.prototype%.asIndexedPairs is a built-in async generator function which, when called, performs the following prelude steps: | ||
Let iterated be ? GetIteratorDirect(this value). | ||
The body of %AsyncIterator.prototype%.asIndexedPairs is composed of the following steps: | ||
Let index be 0. | ||
Let lastValue be undefined. | ||
Repeat, | ||
Let next be ? Await(? IteratorNext(iterated, lastValue)). | ||
If ? IteratorComplete(next) is true, return undefined. | ||
Let value be ? IteratorValue(next). | ||
Let pair be ! CreateArrayFromList(« index, value »). | ||
Set index to index + 1. | ||
Set lastValue to Yield(pair). | ||
IfAbruptCloseAsyncIterator(iterated, lastValue). | ||
features: [async-iteration, iterator-helpers] | ||
flags: [async] | ||
---*/ | ||
let genCount = 0; | ||
|
||
async function* g() { | ||
genCount++; | ||
yield 1; | ||
genCount++; | ||
throw new Test262Error(); | ||
} | ||
|
||
(async () => { | ||
let iterator = g().asIndexedPairs(); | ||
let tryCount = 0; | ||
let catchCount = 0; | ||
let forAwaitCount = 0; | ||
|
||
try { | ||
tryCount++; | ||
|
||
for await (const [i, v] of iterator) { | ||
forAwaitCount++; | ||
} | ||
|
||
tryCount++; | ||
} catch (e) { | ||
catchCount++; | ||
assert.sameValue(e instanceof Test262Error, true, 'The result of `(e instanceof Test262Error)` is true'); | ||
} | ||
|
||
assert.sameValue(genCount, 2, 'The value of `genCount` is 2'); | ||
assert.sameValue(tryCount, 1, 'The value of `tryCount` is 1'); | ||
assert.sameValue(catchCount, 1, 'The value of `catchCount` is 1'); | ||
assert.sameValue(forAwaitCount, 1, 'The value of `forAwaitCount` is 1'); | ||
})().then($DONE, $DONE); |
Oops, something went wrong.