diff options
Diffstat (limited to 'test/built-ins/AsyncGeneratorPrototype')
15 files changed, 794 insertions, 0 deletions
diff --git a/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-promise.js b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-promise.js new file mode 100644 index 000000000..8556d7fd3 --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-promise.js @@ -0,0 +1,50 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-return +description: > + Generator is not resumed after a return type completion. + Returning promise before start +info: | + AsyncGenerator.prototype.return ( value ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: return, [[Value]]: value, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + AsyncGeneratorResumeNext: + If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is + "suspendedStart", generator is closed without being resumed. + + AsyncGeneratorResolve will unwrap Promise values (steps 6-10) +flags: [async] +features: [async-iteration] +---*/ + +var g = async function*() { + throw new Test262Error('Generator must not be resumed.'); +}; + +var it = g(); +var resolve; +var promise = new Promise(function(resolver) { + resolve = resolver; +}); + +it.return(promise).then(function(ret) { + assert.sameValue(ret.value, 'unwrapped-value', 'AsyncGeneratorResolve(generator, completion.[[Value]], true)'); + assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, completion.[[Value]], true)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); +}).catch($DONE); + +resolve('unwrapped-value'); diff --git a/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart.js b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart.js new file mode 100644 index 000000000..f54041c8b --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart.js @@ -0,0 +1,42 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-return +description: > + Generator is not resumed after a return type completion. + Returning non-promise before start +info: | + AsyncGenerator.prototype.return ( value ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: return, [[Value]]: value, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is + "suspendedStart", generator is closed without being resumed. +flags: [async] +features: [async-iteration] +---*/ + +var g = async function*() { + throw new Test262Error('Generator must not be resumed.'); +}; + +var it = g(); +it.return('sent-value').then(function(ret) { + assert.sameValue(ret.value, 'sent-value', 'AsyncGeneratorResolve(generator, completion.[[Value]], true)'); + assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, completion.[[Value]], true)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-promise.js b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-promise.js new file mode 100644 index 000000000..5387e5444 --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-promise.js @@ -0,0 +1,56 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-return +description: > + Generator is not resumed after a return type completion. + Returning promise +info: | + AsyncGenerator.prototype.return ( value ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: return, [[Value]]: value, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is + "suspendedYield", generator is resumed and immediately closes the generator + and returns completion. +flags: [async] +features: [async-iteration] +---*/ + +var g = async function*() { + yield 1; + throw new Test262Error('Generator must not be resumed.'); +}; + +var it = g(); +var resolve; +var promise = new Promise(function(resolver) { + resolve = resolver; +}); +it.next().then(function(ret) { + assert.sameValue(ret.value, 1, 'Initial yield'); + assert.sameValue(ret.done, false, 'Initial yield'); + + it.return(promise).then(function(ret) { + assert.sameValue(ret.value, 'unwrapped-value', 'AsyncGeneratorResolve(generator, resultValue, true)'); + assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, resultValue, true)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); + + }).catch($DONE); + + resolve('unwrapped-value'); +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-return.js b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-return.js new file mode 100644 index 000000000..48052d139 --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-return.js @@ -0,0 +1,55 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-return +description: > + Returned generator suspended in a yield position resumes execution within + an associated finally +info: | + AsyncGenerator.prototype.return ( value ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: return, [[Value]]: value, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is + "suspendedYield", and generator is resumed within a try-block with an + associated finally block, resume execution within finally. +flags: [async] +features: [async-iteration] +---*/ + +var g = async function*() { + try { + yield 1; + throw new Test262Error('Generator must be resumed in finally block.'); + } finally { + return 'done'; + } +}; + +var it = g(); +it.next().then(function(ret) { + assert.sameValue(ret.value, 1, 'Initial yield'); + assert.sameValue(ret.done, false, 'Initial yield'); + + it.return('sent-value').then(function(ret) { + assert.sameValue(ret.value, 'done', 'AsyncGeneratorResolve(generator, resultValue, true)'); + assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, resultValue, true)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); + + }).catch($DONE); + +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-throw.js b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-throw.js new file mode 100644 index 000000000..493f65605 --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-throw.js @@ -0,0 +1,57 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-return +description: > + Returned generator suspended in a yield position resumes execution + within an associated finally, capturing a new abrupt completion and + does not resume again within that finally block. +info: | + AsyncGenerator.prototype.return ( value ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: return, [[Value]]: value, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is + "suspendedYield", and generator is resumed within a try-block with an + associated finally block, resume execution within finally. +flags: [async] +features: [async-iteration] +---*/ + +var error = new Error("boop"); +var g = async function*() { + try { + yield 1; + throw new Test262Error('Generator must be resumed in finally block.'); + } finally { + throw error; + throw new Test262Error('Generator must not be resumed.'); + } +}; + +var it = g(); +it.next().then(function(ret) { + assert.sameValue(ret.value, 1, 'Initial yield'); + assert.sameValue(ret.done, false, 'Initial yield'); + + it.return('sent-value').then($DONE, function(err) { + assert.sameValue(err, error, 'AsyncGeneratorReject(generator, resultValue)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); + + }).catch($DONE); + +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally.js b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally.js new file mode 100644 index 000000000..3660358e3 --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally.js @@ -0,0 +1,61 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-return +description: > + Returned generator suspended in a yield position resumes execution within + an associated finally. +info: | + AsyncGenerator.prototype.return ( value ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: return, [[Value]]: value, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is + "suspendedYield", and generator is resumed within a try-block with an + associated finally block, resume execution within finally. +flags: [async] +features: [async-iteration] +---*/ + +var g = async function*() { + try { + yield 1; + throw new Test262Error('Generator must be resumed in finally block.'); + } finally { + yield 2; + } +}; + +var it = g(); +it.next().then(function(ret) { + assert.sameValue(ret.value, 1, 'Initial yield'); + assert.sameValue(ret.done, false, 'Initial yield'); + + it.return('sent-value').then(function(ret) { + assert.sameValue(ret.value, 2, 'Yield in finally block'); + assert.sameValue(ret.done, false, 'Yield in finally block'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, 'sent-value', 'AsyncGeneratorResolve(generator, resultValue, true)'); + assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, resultValue, true)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); + + }).catch($DONE); + + }).catch($DONE); + +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield.js b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield.js new file mode 100644 index 000000000..21aca35e6 --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield.js @@ -0,0 +1,51 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-return +description: > + Returned generator suspended in a yield position does not resume execution + without an associated finally. +info: | + AsyncGenerator.prototype.return ( value ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: return, [[Value]]: value, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is return, and generator.[[AsyncGeneratorState]] is + "suspendedYield", generator is resumed and immediately closes the generator + and returns completion. +flags: [async] +features: [async-iteration] +---*/ + +var g = async function*() { + yield 1; + throw new Test262Error('Generator must not be resumed.'); +}; + +var it = g(); +it.next().then(function(ret) { + assert.sameValue(ret.value, 1, 'Initial yield'); + assert.sameValue(ret.done, false, 'Initial yield'); + + it.return('sent-value').then(function(ret) { + assert.sameValue(ret.value, 'sent-value', 'AsyncGeneratorResolve(generator, resultValue, true)'); + assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, resultValue, true)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); + + }).catch($DONE); + +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart-promise.js b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart-promise.js new file mode 100644 index 000000000..06fccf685 --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart-promise.js @@ -0,0 +1,45 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-throw +description: > + Generator is not resumed after a throw completion with a promise arg before + start +info: | + AsyncGenerator.prototype.throw ( exception ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: throw, [[Value]]: exception, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is + "suspendedStart", generator is closed without being resumed. + + AsyncGeneratorReject will not unwrap Promise values +flags: [async] +features: [async-iteration] +---*/ + +var g = async function*() { + throw new Test262Error('Generator must not be resumed.'); +}; + +var it = g(); +var promise = new Promise(function() {}); + +it.throw(promise).then($DONE, function(err) { + assert.sameValue(err, promise, 'AsyncGeneratorReject(generator, completion.[[Value]])'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart.js b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart.js new file mode 100644 index 000000000..ef8abdf55 --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart.js @@ -0,0 +1,42 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-throw +description: > + Generator is not resumed after a throw completion with a non-promise arg + before start +info: | + AsyncGenerator.prototype.throw ( exception ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: throw, [[Value]]: exception, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is + "suspendedStart", generator is closed without being resumed. +flags: [async] +features: [async-iteration] +---*/ + +var error = new Error('boop'); +var g = async function*() { + throw new Test262Error('Generator must not be resumed.'); +}; + +var it = g(); +it.throw(error).then($DONE, function(err) { + assert.sameValue(err, error, 'AsyncGeneratorReject(generator, completion.[[Value]])'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-promise.js b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-promise.js new file mode 100644 index 000000000..3948ed65d --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-promise.js @@ -0,0 +1,53 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-throw +description: > + Generator is not resumed after a throw completion with a promise arg +info: | + AsyncGenerator.prototype.throw ( exception ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: throw, [[Value]]: exception, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is + "suspendedYield", generator is resumed and immediately and + closes the generator and returns completion. + + AsyncGeneratorReject will not unwrap Promise values +flags: [async] +features: [async-iteration] +---*/ + +var g = async function*() { + yield 1; + throw new Test262Error('Generator must not be resumed.'); +}; + +var it = g(); +var promise = new Promise(function() {}); + +it.next().then(function(ret) { + assert.sameValue(ret.value, 1, 'Initial yield'); + assert.sameValue(ret.done, false, 'Initial yield'); + + it.throw(promise).then($DONE, function(err) { + assert.sameValue(err, promise, 'AsyncGeneratorReject(generator, resultValue)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); + + }).catch($DONE); + +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-catch.js b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-catch.js new file mode 100644 index 000000000..dad975f7a --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-catch.js @@ -0,0 +1,57 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-throw +description: > + Thrown generator suspended in a yield position resumes execution within + the associated catch-block +info: | + AsyncGenerator.prototype.throw ( exception ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: throw, [[Value]]: exception, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is + "suspendedYield", and generator is resumed within a try-block with an + associated catch block, resume execution within catch-block. +flags: [async] +features: [async-iteration] +---*/ + +var error = new Error('boop'); +var g = async function*() { + try { + yield 1; + throw new Test262Error('Generator must be resumed in catch block.'); + } catch (err) { + assert.sameValue(err, error); + return 'done'; + } +}; + +var it = g(); +it.next().then(function(ret) { + assert.sameValue(ret.value, 1, 'Initial yield'); + assert.sameValue(ret.done, false, 'Initial yield'); + + it.throw(error).then(function(ret) { + assert.sameValue(ret.value, 'done', 'AsyncGeneratorResolve(generator, resultValue, true)'); + assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, resultValue, true)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); + + }).catch($DONE); + +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-return.js b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-return.js new file mode 100644 index 000000000..281aee5d6 --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-return.js @@ -0,0 +1,57 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-throw +description: > + Thrown generator suspended in a yield position resumes execution within + the associated finally block, returns and suspends execution again. +info: | + AsyncGenerator.prototype.throw ( exception ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: throw, [[Value]]: exception, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is + "suspendedYield", and generator is resumed within a try-block with an + associated finally block, resume execution within finally. +flags: [async] +features: [async-iteration] +---*/ + +class Err extends Error {}; +var g = async function*() { + try { + yield 1; + throw new Test262Error('Generator must be resumed in finally block.'); + } finally { + return 'done'; + throw new Test262Error('Generator must not be resumed.'); + } +}; + +var it = g(); +it.next().then(function(ret) { + assert.sameValue(ret.value, 1, 'Initial yield'); + assert.sameValue(ret.done, false, 'Initial yield'); + + it.throw(new Err).then(function(ret) { + assert.sameValue(ret.value, 'done', 'AsyncGeneratorResolve(generator, resultValue, true)'); + assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, resultValue, true)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); + + }).catch($DONE); + +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-throw.js b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-throw.js new file mode 100644 index 000000000..15088f8ff --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-throw.js @@ -0,0 +1,57 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-throw +description: > + Thrown generator suspended in a yield position resumes execution within + the associated finally block and throws an error and suspendeds execution + again +info: | + AsyncGenerator.prototype.throw ( exception ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: throw, [[Value]]: exception, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is + "suspendedYield", and generator is resumed within a try-block with an + associated finally block, resume execution within finally. +flags: [async] +features: [async-iteration] +---*/ + +var error = new Error('boop'); +var g = async function*() { + try { + yield 1; + throw new Test262Error('Generator must be resumed in finally block.'); + } finally { + throw error; + throw new Test262Error('Generator must not be resumed.'); + } +}; + +var it = g(); +it.next().then(function(ret) { + assert.sameValue(ret.value, 1, 'Initial yield'); + assert.sameValue(ret.done, false, 'Initial yield'); + + it.throw(new Error('superceded')).then($DONE, function(err) { + assert.sameValue(err, error, 'AsyncGeneratorReject(generator, resultValue)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); + + }).catch($DONE); + +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally.js b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally.js new file mode 100644 index 000000000..3ec534a3a --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally.js @@ -0,0 +1,61 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-throw +description: > + Thrown generator suspended in a yield position resumes execution within + the associated finally block. +info: | + AsyncGenerator.prototype.throw ( exception ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: throw, [[Value]]: exception, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is + "suspendedYield", and generator is resumed within a try-block with an + associated finally block, resume execution within finally. +flags: [async] +features: [async-iteration] +---*/ + +var error = new Error('boop'); +var g = async function*() { + try { + yield 1; + throw new Test262Error('Generator must be resumed in finally block.'); + } finally { + yield 2; + } +}; + +var it = g(); +it.next().then(function(ret) { + assert.sameValue(ret.value, 1, 'Initial yield'); + assert.sameValue(ret.done, false, 'Initial yield'); + + it.throw(error).then(function(ret) { + assert.sameValue(ret.value, 2, 'Yield in finally block'); + assert.sameValue(ret.done, false, 'Yield in finally block'); + + it.next().then($DONE, function(err) { + assert.sameValue(err, error, 'AsyncGeneratorReject(generator, returnValue)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); + + }).catch($DONE); + + }).catch($DONE); + +}).catch($DONE); diff --git a/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield.js b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield.js new file mode 100644 index 000000000..b413285bc --- /dev/null +++ b/test/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield.js @@ -0,0 +1,50 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Caitlin Potter <caitp@igalia.com> +esid: sec-asyncgenerator-prototype-throw +description: > + Generator is not resumed after a throw completion with an error object +info: | + AsyncGenerator.prototype.throw ( exception ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: throw, [[Value]]: exception, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 8. If state is not "executing", then + a. Perform ! AsyncGeneratorResumeNext(generator). + ... + + AsyncGeneratorResumeNext: + If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is + "suspendedYield", generator is resumed and immediately and + closes the generator and returns completion. +flags: [async] +features: [async-iteration] +---*/ + +var error = new Error('boop'); +var g = async function*() { + yield 1; + throw new Test262Error('Generator must not be resumed.'); +}; + +var it = g(); +it.next().then(function(ret) { + assert.sameValue(ret.value, 1, 'Initial yield'); + assert.sameValue(ret.done, false, 'Initial yield'); + + it.throw(error).then($DONE, function(err) { + assert.sameValue(err, error, 'AsyncGeneratorReject(generator, resultValue)'); + + it.next().then(function(ret) { + assert.sameValue(ret.value, undefined, 'Generator is closed'); + assert.sameValue(ret.done, true, 'Generator is closed'); + }).then($DONE, $DONE); + + }).catch($DONE); + +}).catch($DONE); |