From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../AsyncGeneratorPrototype/throw/browser.js | 0 .../AsyncGeneratorPrototype/throw/length.js | 37 ++++++++ .../AsyncGeneratorPrototype/throw/name.js | 33 +++++++ .../AsyncGeneratorPrototype/throw/prop-desc.js | 23 +++++ .../throw/request-queue-order-state-executing.js | 69 ++++++++++++++ .../throw/return-rejected-promise.js | 55 ++++++++++++ .../AsyncGeneratorPrototype/throw/shell.js | 0 .../throw/this-val-not-async-generator.js | 90 +++++++++++++++++++ .../throw/this-val-not-object.js | 100 +++++++++++++++++++++ .../throw/throw-state-completed.js | 39 ++++++++ .../throw/throw-suspendedStart-promise.js | 46 ++++++++++ .../throw/throw-suspendedStart.js | 43 +++++++++ .../throw/throw-suspendedYield-promise.js | 54 +++++++++++ .../throw/throw-suspendedYield-try-catch.js | 58 ++++++++++++ .../throw-suspendedYield-try-finally-return.js | 58 ++++++++++++ .../throw-suspendedYield-try-finally-throw.js | 58 ++++++++++++ .../throw/throw-suspendedYield-try-finally.js | 62 +++++++++++++ .../throw/throw-suspendedYield.js | 51 +++++++++++ 18 files changed, 876 insertions(+) create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/browser.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/length.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/name.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/prop-desc.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/request-queue-order-state-executing.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/return-rejected-promise.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/shell.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/this-val-not-async-generator.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/this-val-not-object.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-state-completed.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart-promise.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-promise.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-catch.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-return.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-throw.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally.js create mode 100644 js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield.js (limited to 'js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw') diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/browser.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/length.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/length.js new file mode 100644 index 0000000000..a7fb3538e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/length.js @@ -0,0 +1,37 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-asyncgenerator-prototype-throw +description: > + AsyncGenerator.prototype.throw.length is 1. +info: | + AsyncGenerator.prototype.throw ( value ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [async-iteration] +---*/ + +async function* g() {} +var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype; + +verifyProperty(AsyncGeneratorPrototype.throw, "length", { + value: 1, + enumerable: false, + writable: false, + configurable: true, +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/name.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/name.js new file mode 100644 index 0000000000..0a1174c8b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/name.js @@ -0,0 +1,33 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-asyncgenerator-prototype-throw +description: > + Generator.prototype.next.name is "throw". +info: | + Generator.prototype.throw ( value ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [async-iteration] +---*/ + +async function* g() {} +var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype; + +verifyProperty(AsyncGeneratorPrototype.throw, "name", { + value: "throw", + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/prop-desc.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/prop-desc.js new file mode 100644 index 0000000000..61456bfe7c --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/prop-desc.js @@ -0,0 +1,23 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-asyncgenerator-prototype-thow +description: GeneratorPrototype.throw property description +info: | + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [async-iteration] +---*/ + +async function* g() {} +var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype; + +verifyProperty(AsyncGeneratorPrototype, "throw", { + enumerable: false, + writable: true, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/request-queue-order-state-executing.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/request-queue-order-state-executing.js new file mode 100644 index 0000000000..b61667aec3 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/request-queue-order-state-executing.js @@ -0,0 +1,69 @@ +// |reftest| async +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-asyncgenerator-prototype-throw +description: return() call while iterator is in state executing +info: | + AsyncGenerator.prototype.throw ( error ) + 1. Let generator be the this value. + 2. Let completion be Completion{[[Type]]: throw, [[Value]]: error, [[Target]]: empty}. + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 4. Let queue be generator.[[AsyncGeneratorQueue]]. + 5. Let request be AsyncGeneratorRequest{[[Completion]]: completion, + [[Capability]]: promiseCapability}. + 6. Append request to the end of queue. + ... + + AsyncGeneratorResolve ( generator, value, done ) + ... + 2. Let queue be generator.[[AsyncGeneratorQueue]]. + 3. Assert: queue is not an empty List. + 4. Remove the first element from queue and let next be the value of that element. + ... + +flags: [async] +features: [async-iteration] +---*/ + +var iter, result; +var thrownErr = new Error("Catch me."); +var caughtErr; + +var order = 0; +var promises = [] + +async function* g() { + + iter.throw(thrownErr).then( + function() { + $DONE(new Test262Error("throw() should result in reject promise.")); + }, + function(e) { + caughtErr = e; + order++; + } + ); + + yield 1; + yield 2; +} + +iter = g(); + +iter.next().then(function(result) { + + assert.sameValue(++order, 1); + assert.sameValue(result.value, 1); + assert.sameValue(result.done, false); + + iter.next().then(function(result) { + assert.sameValue(++order, 3); + assert.sameValue(caughtErr, thrownErr); + assert.sameValue(result.done, true); + }).then($DONE, $DONE); + +}).catch($DONE) diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/return-rejected-promise.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/return-rejected-promise.js new file mode 100644 index 0000000000..318cd01fad --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/return-rejected-promise.js @@ -0,0 +1,55 @@ +// |reftest| async +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-asyncgenerator-prototype-throw +description: > + "throw" returns a rejected promise +info: | + AsyncGenerator.prototype.next ( value ) + 1. Let generator be the this value. + 2. Let completion be NormalCompletion(value). + 3. Return ! AsyncGeneratorEnqueue(generator, completion). + + AsyncGeneratorEnqueue ( generator, completion ) + ... + 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). + ... + 4. Let queue be generator.[[AsyncGeneratorQueue]]. + 5. Let request be AsyncGeneratorRequest{[[Completion]]: completion, + [[Capability]]: promiseCapability}. + 6. Append request to the end of queue. + ... + 9. Return promiseCapability.[[Promise]]. + + AsyncGeneratorReject ( generator, exception ) + 1. Assert: generator is an AsyncGenerator instance. + 2. Let queue be generator.[[AsyncGeneratorQueue]]. + 3. Assert: queue is not an empty List. + 4. Remove the first element from queue and let next be the value of that element. + 5. Let promiseCapability be next.[[Capability]]. + 6. Perform ! Call(promiseCapability.[[Reject]], undefined, « exception »). + ... + +flags: [async] +features: [async-iteration] +---*/ + +async function* g() {} + +var errormessage = "Promise rejected." +var result = g().throw(new Test262Error(errormessage)) + +assert(result instanceof Promise, "Expected result to be an instanceof Promise") + +result.then( + function () { + throw new Test262Error("Expected result to be rejected promise."); + }, + function (e) { + if (!(e.message = errormessage)) { + throw new Test262Error("Expected thrown custom error, got " + e); + } + } +).then($DONE, $DONE) diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/shell.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/this-val-not-async-generator.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/this-val-not-async-generator.js new file mode 100644 index 0000000000..65ef63e8b6 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/this-val-not-async-generator.js @@ -0,0 +1,90 @@ +// |reftest| async +// Copyright 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-asyncgenerator-prototype-throw +description: throw rejects promise when `this` value is not an async generator +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 ) + ... + 3. If Type(generator) is not Object, or if generator does not have an + [[AsyncGeneratorState]] internal slot, then + a. Let badGeneratorError be a newly created TypeError object. + b. Perform ! Call(promiseCapability.[[Reject]], undefined, « badGeneratorError »). + c. Return promiseCapability.[[Promise]]. + +flags: [async] +features: [async-iteration] +---*/ + +async function* g() {} +var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype; + +function* syncGenerator() {} +var syncIterator = syncGenerator() + +var testPromises = [ + AsyncGeneratorPrototype.throw.call({}).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" + + " when `this` value is an object"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(object) expected TypeError but got " + e); + } + } + ), + AsyncGeneratorPrototype.throw.call(function() {}).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" + + " when `this` value is a function"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(function) expected TypeError but got " + e); + } + } + ), + AsyncGeneratorPrototype.throw.call(g).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" + + " when `this` value is an async generator function"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(async generator function) expected TypeError but got " + e); + } + } + ), + AsyncGeneratorPrototype.throw.call(g.prototype).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" + + " when `this` value is an async generator function prototype object"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(async generator function prototype) expected TypeError but got " + e); + } + }, + ), + AsyncGeneratorPrototype.throw.call(syncIterator).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" + + " when `this` value is a generator"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(generator) expected TypeError but got " + e); + } + } + ) +] + +Promise.all(testPromises).then(() => {}).then($DONE, $DONE) diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/this-val-not-object.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/this-val-not-object.js new file mode 100644 index 0000000000..cb4bbbb3d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/this-val-not-object.js @@ -0,0 +1,100 @@ +// |reftest| async +// Copyright 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-asyncgenerator-prototype-throw +description: throw rejects promise when `this` value not an 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 ) + ... + 3. If Type(generator) is not Object, or if generator does not have an + [[AsyncGeneratorState]] internal slot, then + a. Let badGeneratorError be a newly created TypeError object. + b. Perform ! Call(promiseCapability.[[Reject]], undefined, « badGeneratorError »). + c. Return promiseCapability.[[Promise]]. + +flags: [async] +features: [async-iteration] +---*/ + +async function* g() {} +var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype; + +var symbol = Symbol(); + +var testPromises = [ + AsyncGeneratorPrototype.throw.call(undefined).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" + + " when `this` value `undefined`"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(undefined) expected TypeError but got " + e); + } + } + ), + AsyncGeneratorPrototype.throw.call(1).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" + + " when `this` value is a Number"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(Number) expected TypeError but got " + e); + } + } + ), + AsyncGeneratorPrototype.throw.call("string").then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" + + " when `this` value is a String"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(String) expected TypeError but got " + e); + } + } + ), + AsyncGeneratorPrototype.throw.call(null).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" + + " when `this` value `null`"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(null) expected TypeError but got " + e); + } + } + ), + AsyncGeneratorPrototype.throw.call(true).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" + + " when `this` value is a Boolean"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(Boolean) expected TypeError but got " + e); + } + } + ), + AsyncGeneratorPrototype.throw.call(symbol).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" + + " when `this` value is a Symbol"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(Symbol) expected TypeError but got " + e); + } + } + ) +] + +Promise.all(testPromises).then(() => {}).then($DONE, $DONE) diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-state-completed.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-state-completed.js new file mode 100644 index 0000000000..c2c02e596c --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-state-completed.js @@ -0,0 +1,39 @@ +// |reftest| async +// Copyright 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-asyncgenerator-prototype-throw +description: throw() results in rejected promise when called on completed iterator +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 + "completed", the resulting promise is rejected with the error. +flags: [async] +features: [async-iteration] +---*/ + +var throwError = new Error('Catch me'); +var g = async function*() {}; + +var iter = g(); +iter.next().then(function(result) { + assert.sameValue(result.value, undefined); + assert.sameValue(result.done, true); + + iter.throw(throwError).then($DONE, function(err) { + assert.sameValue(err, throwError) + }).then($DONE, $DONE); + +}).catch($DONE); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart-promise.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart-promise.js new file mode 100644 index 0000000000..d792ac630d --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart-promise.js @@ -0,0 +1,46 @@ +// |reftest| async +// 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 +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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart.js new file mode 100644 index 0000000000..c8c938e219 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart.js @@ -0,0 +1,43 @@ +// |reftest| async +// 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 +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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-promise.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-promise.js new file mode 100644 index 0000000000..20871194f9 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-promise.js @@ -0,0 +1,54 @@ +// |reftest| async +// 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 +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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-catch.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-catch.js new file mode 100644 index 0000000000..88a48ae919 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-catch.js @@ -0,0 +1,58 @@ +// |reftest| async +// 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 +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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-return.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-return.js new file mode 100644 index 0000000000..7a2483fbf9 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-return.js @@ -0,0 +1,58 @@ +// |reftest| async +// 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 +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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-throw.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-throw.js new file mode 100644 index 0000000000..b29b2b8c08 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-throw.js @@ -0,0 +1,58 @@ +// |reftest| async +// 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 +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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally.js new file mode 100644 index 0000000000..56121f6856 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally.js @@ -0,0 +1,62 @@ +// |reftest| async +// 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 +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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield.js new file mode 100644 index 0000000000..fb24973127 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield.js @@ -0,0 +1,51 @@ +// |reftest| async +// 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 +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); -- cgit v1.2.3