diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/AsyncGeneratorPrototype | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/AsyncGeneratorPrototype')
56 files changed, 2730 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/Symbol.toStringTag.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/Symbol.toStringTag.js new file mode 100644 index 0000000000..b725467f5f --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/Symbol.toStringTag.js @@ -0,0 +1,30 @@ +// 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-tostringtag +description: > + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the String value + "AsyncGenerator". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. + +includes: [propertyHelper.js] +features: [async-iteration, Symbol.toStringTag] +---*/ + +var AsyncGeneratorPrototype = Object.getPrototypeOf( + Object.getPrototypeOf(async function*() {}()) +); + +verifyProperty(AsyncGeneratorPrototype, Symbol.toStringTag, { + value: 'AsyncGenerator', + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/browser.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/browser.js diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/constructor.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/constructor.js new file mode 100644 index 0000000000..d648b672af --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/constructor.js @@ -0,0 +1,32 @@ +// 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-constructor +description: > + The GeneratorPrototype intrinsic's constructor. +info: | + AsyncGenerator.prototype.constructor + + The initial value of AsyncGenerator.prototype.constructor is the + intrinsic object %AsyncGenerator%. + + This property has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. + +includes: [propertyHelper.js] +features: [async-iteration] +---*/ + +async function* g() {} +var AsyncGenerator = Object.getPrototypeOf(g); +var AsyncGeneratorPrototype = AsyncGenerator.prototype; + +verifyProperty(AsyncGeneratorPrototype, 'constructor', { + value: AsyncGenerator, + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/browser.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/browser.js diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/iterator-result-prototype.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/iterator-result-prototype.js new file mode 100644 index 0000000000..5cd181fd6e --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/iterator-result-prototype.js @@ -0,0 +1,47 @@ +// |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-next +description: > + "next" returns a promise for an IteratorResult object +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 ) + ... + 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 ) + 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. Let iteratorResult be ! CreateIterResultObject(value, done). + 7. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iteratorResult »). + ... + +flags: [async] +features: [async-iteration] +---*/ + +async function* g() {} + +g().next().then(function (result) { + assert( + Object.prototype.hasOwnProperty.call(result, 'value'), 'Has "own" property `value`' + ); + assert( + Object.prototype.hasOwnProperty.call(result, 'done'), 'Has "own" property `done`' + ); + assert.sameValue(Object.getPrototypeOf(result), Object.prototype); +}).then($DONE, $DONE) diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/length.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/length.js new file mode 100644 index 0000000000..0728576a86 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/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-next +description: > + AsyncGenerator.prototype.next.length is 1. +info: | + AsyncGenerator.prototype.next ( 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.next, "length", { + value: 1, + enumerable: false, + writable: false, + configurable: true, +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/name.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/name.js new file mode 100644 index 0000000000..f7351289e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/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-next +description: > + Generator.prototype.next.name is "next". +info: | + Generator.prototype.next ( 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.next, "name", { + value: "next", + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/prop-desc.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/prop-desc.js new file mode 100644 index 0000000000..3eabb2efa2 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/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-next +description: GeneratorPrototype.next 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, "next", { + enumerable: false, + writable: true, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/request-queue-await-order.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/request-queue-await-order.js new file mode 100644 index 0000000000..e3bf75efbf --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/request-queue-await-order.js @@ -0,0 +1,68 @@ +// |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-next +description: next() requests from iterator processed in order, await +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 ) + ... + 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] +includes: [asyncHelpers.js] +---*/ + +var yieldorder = 0; +var resolveLatePromise; + +function resolveLater() { + return new Promise(resolve => { + resolveLatePromise = resolve; + }); +} + +async function* g() { + yield resolveLater(); + yield ++yieldorder; +} + +var iter = g(); + +assert.sameValue(yieldorder, 0); + +var item1 = iter.next(); +var item2 = iter.next(); +var item3 = iter.next(); + +async function awaitnexts() { + assert.sameValue((await item3).value, undefined) + assert.sameValue(yieldorder, 2, "All next requests have been proccessed.") + assert.sameValue((await item2).value, 2) + assert.sameValue((await item1).value, 1) +} + +asyncTest(awaitnexts); + +// At this point: +// yieldorder == 0 +// item1 is an unresolved promise +resolveLatePromise(++yieldorder); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/request-queue-order-state-executing.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/request-queue-order-state-executing.js new file mode 100644 index 0000000000..6aa188ea72 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/request-queue-order-state-executing.js @@ -0,0 +1,72 @@ +// |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: next() call while iterator is in state executing +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 ) + ... + 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 executionorder = 0; +var valueisset = false; + +async function* g() { + + iter.next().then( + function(result) { + assert(valueisset, "variable valueisset should be set to true"); + assert.sameValue(++executionorder, 2); + assert.sameValue(result.value, 2); + assert.sameValue(result.done, false); + }, + function() { + $DONE(new Test262Error("next() should result in resolved promise.")); + } + ).catch($DONE) + + valueisset = true; + + yield 1; + yield 2; +} + +iter = g(); + +iter.next().then(function(result) { + assert.sameValue(++executionorder, 1); + assert.sameValue(result.value, 1); + assert.sameValue(result.done, false); + + iter.next().then(function(result) { + assert.sameValue(++executionorder, 3); + assert.sameValue(result.value, undefined); + assert.sameValue(result.done, true); + }).then($DONE, $DONE); + +}).catch($DONE); + + + diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/request-queue-order.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/request-queue-order.js new file mode 100644 index 0000000000..22b56b1dfc --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/request-queue-order.js @@ -0,0 +1,72 @@ +// |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-next +description: queue +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 ) + ... + 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 order = 0; + +async function* g() { + yield 'first'; + yield 'second'; +} + +var iter = g(); + +var item1 = iter.next(); +var item2 = iter.next(); +var item3 = iter.next(); + +var resolvedorder = 0; + +Promise.all([ + + item3.then(function(result) { + resolvedorder++; + assert.sameValue(resolvedorder, 3); + assert.sameValue(result.value, undefined); + assert.sameValue(result.done, true); + }), + + item2.then(function(result) { + resolvedorder++; + assert.sameValue(resolvedorder, 2); + assert.sameValue(result.value, "second"); + assert.sameValue(result.done, false); + }), + + item1.then(function(result) { + resolvedorder++; + assert.sameValue(resolvedorder, 1); + assert.sameValue(result.value, "first"); + assert.sameValue(result.done, false); + }) + +]).then(function() { $DONE(); }, $DONE); + diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/request-queue-promise-resolve-order.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/request-queue-promise-resolve-order.js new file mode 100644 index 0000000000..2f610ccbcc --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/request-queue-promise-resolve-order.js @@ -0,0 +1,83 @@ +// |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-next +description: next() requests from iterator processed in order, then +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 ) + ... + 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 yieldorder = 0; +var resolveLatePromise; + +function resolveLater() { + return new Promise(resolve => { + resolveLatePromise = resolve; + }); +} + +async function* g() { + yield resolveLater(); + yield ++yieldorder; +} + +var iter = g(); + +var item1 = iter.next(); +var item2 = iter.next(); +var item3 = iter.next(); + +var resolvedorder = 0; + +Promise.all([ + + item3.then(function(result) { + resolvedorder++; + assert.sameValue(resolvedorder, 3); + assert.sameValue(result.value, undefined); + assert.sameValue(result.done, true); + }), + + item2.then(function(result) { + resolvedorder++; + assert.sameValue(resolvedorder, 2); + assert.sameValue(result.value, 2); + assert.sameValue(result.done, false); + }), + + item1.then(function(result) { + resolvedorder++; + assert.sameValue(resolvedorder, 1); + assert.sameValue(result.value, 1); + assert.sameValue(result.done, false); + }) + +]).then(function() { $DONE(); }, $DONE); + +// At this point: +// yieldorder == 0 +// item1 is an unresolved promise +resolveLatePromise(++yieldorder); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/return-promise.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/return-promise.js new file mode 100644 index 0000000000..b6b0689408 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/return-promise.js @@ -0,0 +1,28 @@ +// 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-next +description: > + "next" returns a promise for an IteratorResult object +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%). + ... + 9. Return promiseCapability.[[Promise]]. + +features: [async-iteration] +---*/ + +async function* g() {} +var result = g().next() + +assert(result instanceof Promise) + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/shell.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/shell.js new file mode 100644 index 0000000000..ae18ad584d --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/shell.js @@ -0,0 +1,113 @@ +// GENERATED, DO NOT EDIT +// file: asyncHelpers.js +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A collection of assertion and wrapper functions for testing asynchronous built-ins. +defines: [asyncTest] +---*/ + +function asyncTest(testFunc) { + if (!Object.hasOwn(globalThis, "$DONE")) { + throw new Test262Error("asyncTest called without async flag"); + } + if (typeof testFunc !== "function") { + $DONE(new Test262Error("asyncTest called with non-function argument")); + return; + } + try { + testFunc().then( + function () { + $DONE(); + }, + function (error) { + $DONE(error); + } + ); + } catch (syncError) { + $DONE(syncError); + } +} + +assert.throwsAsync = async function (expectedErrorConstructor, func, message) { + var innerThenable; + if (message === undefined) { + message = ""; + } else { + message += " "; + } + if (typeof func === "function") { + try { + innerThenable = func(); + if ( + innerThenable === null || + typeof innerThenable !== "object" || + typeof innerThenable.then !== "function" + ) { + message += + "Expected to obtain an inner promise that would reject with a" + + expectedErrorConstructor.name + + " but result was not a thenable"; + throw new Test262Error(message); + } + } catch (thrown) { + message += + "Expected a " + + expectedErrorConstructor.name + + " to be thrown asynchronously but an exception was thrown synchronously while obtaining the inner promise"; + throw new Test262Error(message); + } + } else { + message += + "assert.throwsAsync called with an argument that is not a function"; + throw new Test262Error(message); + } + + try { + return innerThenable.then( + function () { + message += + "Expected a " + + expectedErrorConstructor.name + + " to be thrown asynchronously but no exception was thrown at all"; + throw new Test262Error(message); + }, + function (thrown) { + var expectedName, actualName; + if (typeof thrown !== "object" || thrown === null) { + message += "Thrown value was not an object!"; + throw new Test262Error(message); + } else if (thrown.constructor !== expectedErrorConstructor) { + expectedName = expectedErrorConstructor.name; + actualName = thrown.constructor.name; + if (expectedName === actualName) { + message += + "Expected a " + + expectedName + + " but got a different error constructor with the same name"; + } else { + message += + "Expected a " + expectedName + " but got a " + actualName; + } + throw new Test262Error(message); + } + } + ); + } catch (thrown) { + if (typeof thrown !== "object" || thrown === null) { + message += + "Expected a " + + expectedErrorConstructor.name + + " to be thrown asynchronously but innerThenable synchronously threw a value that was not an object "; + } else { + message += + "Expected a " + + expectedErrorConstructor.name + + " to be thrown asynchronously but a " + + thrown.constructor.name + + " was thrown synchronously"; + } + throw new Test262Error(message); + } +}; diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/this-val-not-async-generator.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/this-val-not-async-generator.js new file mode 100644 index 0000000000..a45d1f71ae --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/this-val-not-async-generator.js @@ -0,0 +1,89 @@ +// |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-next +description: next rejects promise when `this` value is not an async generator +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 ) + ... + 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.next.call({}).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.next 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.next.call(function() {}).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.next 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.next.call(g).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.next 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.next.call(g.prototype).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.next 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.next.call(syncIterator).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.next 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/next/this-val-not-object.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/this-val-not-object.js new file mode 100644 index 0000000000..65b8e86cc2 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/next/this-val-not-object.js @@ -0,0 +1,99 @@ +// |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-next +description: next rejects promise when `this` value not an object +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 ) + ... + 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.next.call(undefined).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" + + " when `this` value `undefined`"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(undefined) expected TypeError but got " + e); + } + } + ), + AsyncGeneratorPrototype.next.call(1).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.next 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.next.call("string").then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.next 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.next.call(null).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" + + " when `this` value `null`"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(null) expected TypeError but got " + e); + } + } + ), + AsyncGeneratorPrototype.next.call(true).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.next 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.next.call(symbol).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.next 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/return/browser.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/browser.js diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/iterator-result-prototype.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/iterator-result-prototype.js new file mode 100644 index 0000000000..39af19d852 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/iterator-result-prototype.js @@ -0,0 +1,48 @@ +// |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-return +description: > + "return" returns a promise for an IteratorResult object +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 ) + ... + 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 ) + 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. Let iteratorResult be ! CreateIterResultObject(value, done). + 7. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iteratorResult »). + ... + +flags: [async] +features: [async-iteration] +---*/ + +async function* g() {} + +g().return().then(function (result) { + assert( + Object.prototype.hasOwnProperty.call(result, 'value'), 'Has "own" property `value`' + ); + assert( + Object.prototype.hasOwnProperty.call(result, 'done'), 'Has "own" property `done`' + ); + assert.sameValue(Object.getPrototypeOf(result), Object.prototype); +}).then($DONE, $DONE) diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/length.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/length.js new file mode 100644 index 0000000000..2c1ad56883 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/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-return +description: > + AsyncGenerator.prototype.return.length is 1. +info: | + AsyncGenerator.prototype.return ( 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.return, "length", { + value: 1, + enumerable: false, + writable: false, + configurable: true, +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/name.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/name.js new file mode 100644 index 0000000000..6a7dc5885a --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/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-return +description: > + Generator.prototype.next.name is "return". +info: | + Generator.prototype.return ( 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.return, "name", { + value: "return", + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/prop-desc.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/prop-desc.js new file mode 100644 index 0000000000..4b5b53992e --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/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.return 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, "return", { + enumerable: false, + writable: true, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/request-queue-order-state-executing.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/request-queue-order-state-executing.js new file mode 100644 index 0000000000..8a75a08636 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/request-queue-order-state-executing.js @@ -0,0 +1,67 @@ +// |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.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 ) + ... + 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; +var executionorder = 0; +var valueisset = false; + +async function* g() { + + iter.return(42).then( + function(result) { + assert(valueisset, "variable valueisset should be set to true"); + assert.sameValue(++executionorder, 2); + assert.sameValue(result.value, 42); + assert.sameValue(result.done, true); + } + ).catch($DONE); + + valueisset = true; + + yield 1; + throw new Test262Error("This line should no be reached: generator closed by return"); +} + +iter = g(); + +iter.next().then(function(result) { + + assert.sameValue(++executionorder, 1); + assert.sameValue(result.value, 1); + assert.sameValue(result.done, false); + + iter.next().then(function(result) { + assert.sameValue(++executionorder, 3); + assert.sameValue(result.value, undefined); + assert.sameValue(result.done, true); + }).then($DONE, $DONE); + +}).catch($DONE); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-promise.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-promise.js new file mode 100644 index 0000000000..b29759c921 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-promise.js @@ -0,0 +1,29 @@ +// 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-next +description: > + "return" returns a 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 ) + ... + 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). + ... + 9. Return promiseCapability.[[Promise]]. + +features: [async-iteration] +---*/ + +async function* g() {} +var result = g().return() + +assert(result instanceof Promise) + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-state-completed-broken-promise.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-state-completed-broken-promise.js new file mode 100644 index 0000000000..ad7b3cd6e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-state-completed-broken-promise.js @@ -0,0 +1,63 @@ +// |reftest| async +// Copyright (C) 2022 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-asyncgenerator-prototype-return +description: > + A broken promise should reject the returned promise of + AsyncGenerator.prototype.return when the generator is completed. +info: | + AsyncGenerator.prototype.return ( value ) + ... + 8. If state is either suspendedStart or completed, then + a. Set generator.[[AsyncGeneratorState]] to awaiting-return. + b. Perform ! AsyncGeneratorAwaitReturn(generator). + ... + + AsyncGeneratorAwaitReturn ( generator ) + ... + 6. Let promise be Completion(PromiseResolve(%Promise%, completion.[[Value]])). + 7. If promiseCompletion is an abrupt completion, then + a. Set generator.[[AsyncGeneratorState]] to completed. + b. Perform AsyncGeneratorCompleteStep(generator, promiseCompletion, true). + c. Perform AsyncGeneratorDrainQueue(generator). + d. Return unused. + 8. Assert: promiseCompletion.[[Type]] is normal. + 9. Let promise be promiseCompletion.[[Value]]. + ... + +flags: [async] +features: [async-iteration] +---*/ + +let unblock; +let blocking = new Promise(resolve => { unblock = resolve; }); +let unblocked = false; +var g = async function*() { + await blocking; + unblocked = true; +}; + +var it = g(); +let brokenPromise = Promise.resolve(42); +Object.defineProperty(brokenPromise, 'constructor', { + get: function () { + throw new Error('broken promise'); + } +}); + +it.next(); +it.return(brokenPromise) + .then( + () => { + throw new Test262Error("Expected rejection"); + }, + err => { + assert(unblocked, false, 'return should be rejected before generator is resumed'); + assert.sameValue(err.message, 'broken promise'); + } + ) + .then($DONE, $DONE); + +unblock(); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-state-completed.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-state-completed.js new file mode 100644 index 0000000000..c4cb8b6559 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-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-return +description: return() results in fullfilled promise when called on completed iterator +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 throw, and generator.[[AsyncGeneratorState]] is + "completed" +flags: [async] +features: [async-iteration] +---*/ + +var g = async function*() {}; + +var iter = g(); +iter.next().then(function(result) { + assert.sameValue(result.value, undefined); + assert.sameValue(result.done, true); + + iter.return(42).then(function(result) { + assert.sameValue(result.value, 42) + assert.sameValue(result.done, true) + }).then($DONE, $DONE); + +}).catch($DONE); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-broken-promise.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-broken-promise.js new file mode 100644 index 0000000000..ff35f0af31 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-broken-promise.js @@ -0,0 +1,55 @@ +// |reftest| async +// Copyright (C) 2022 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-asyncgenerator-prototype-return +description: > + A broken promise should reject the returned promise of + AsyncGenerator.prototype.return when the generator's state is suspendedStart. +info: | + AsyncGenerator.prototype.return ( value ) + ... + 8. If state is either suspendedStart or completed, then + a. Set generator.[[AsyncGeneratorState]] to awaiting-return. + b. Perform AsyncGeneratorAwaitReturn(_generator_). + ... + + AsyncGeneratorAwaitReturn ( generator ) + ... + 6. Let promise be Completion(PromiseResolve(%Promise%, completion.[[Value]])). + 7. If promiseCompletion is an abrupt completion, then + a. Set generator.[[AsyncGeneratorState]] to completed. + b. Perform AsyncGeneratorCompleteStep(generator, promiseCompletion, true). + c. Perform AsyncGeneratorDrainQueue(generator). + d. Return unused. + 8. Assert: promiseCompletion.[[Type]] is normal. + 9. Let promise be promiseCompletion.[[Value]]. + ... + +flags: [async] +features: [async-iteration] +---*/ + +var g = async function*() { + throw new Test262Error('Generator must not be resumed.'); +}; + +var it = g(); +let brokenPromise = Promise.resolve(42); +Object.defineProperty(brokenPromise, 'constructor', { + get: function () { + throw new Error('broken promise'); + } +}); + +it.return(brokenPromise) + .then( + () => { + throw new Test262Error("Expected rejection"); + }, + err => { + assert.sameValue(err.message, 'broken promise'); + } + ) + .then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-promise.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-promise.js new file mode 100644 index 0000000000..9e347b771c --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-promise.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 <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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart.js new file mode 100644 index 0000000000..3f3c7e979a --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-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 <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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-broken-promise-try-catch.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-broken-promise-try-catch.js new file mode 100644 index 0000000000..c105dfd70b --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-broken-promise-try-catch.js @@ -0,0 +1,65 @@ +// |reftest| async +// Copyright (C) 2022 Chengzhong Wu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-asyncgenerator-prototype-return +description: > + A broken promise should resume the generator and reject with + the exception when the generator's state is suspendedYield. +info: | + AsyncGenerator.prototype.return ( value ) + ... + 9. Else if state is suspendedYield, then + a. Perform AsyncGeneratorResume(generator, completion). + ... + + AsyncGeneratorCompleteStep ( generator, completion, done [ , realm ] ) + Resumes the steps defined at AsyncGeneratorStart ( generator, generatorBody ) + ... + 4. Set the code evaluation state of genContext such that when evaluation is resumed for that execution context the following steps will be performed: + ... + i. Perform AsyncGeneratorDrainQueue(generator). + j. Return undefined. + + AsyncGeneratorDrainQueue ( generator ) + ... + 5. Repeat, while done is false, + a. Let next be the first element of queue. + b. Let completion be Completion(next.[[Completion]]). + c. If completion.[[Type]] is return, then + i. Set generator.[[AsyncGeneratorState]] to awaiting-return. + ii. Perform AsyncGeneratorAwaitReturn(generator). + iii. Set done to true. + ... + +flags: [async] +features: [async-iteration] +---*/ + +let caughtErr; +var g = async function*() { + try { + yield; + return 'this is never returned'; + } catch (err) { + caughtErr = err; + return 1; + } +}; + +let brokenPromise = Promise.resolve(42); +Object.defineProperty(brokenPromise, 'constructor', { + get: function () { + throw new Error('broken promise'); + } +}); + +var it = g(); +it.next().then(() => { + return it.return(brokenPromise); +}).then(ret => { + assert.sameValue(caughtErr.message, 'broken promise'); + assert.sameValue(ret.value, 1, 'returned value'); + assert.sameValue(ret.done, true, 'iterator is closed'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-promise.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-promise.js new file mode 100644 index 0000000000..45d312688d --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-promise.js @@ -0,0 +1,57 @@ +// |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 <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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-return.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-return.js new file mode 100644 index 0000000000..218fdf2dc2 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-return.js @@ -0,0 +1,56 @@ +// |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 <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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-throw.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-throw.js new file mode 100644 index 0000000000..e708c9a2d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-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 <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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally.js new file mode 100644 index 0000000000..59cfeb61a5 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-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 <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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield.js new file mode 100644 index 0000000000..3b6f3d8aca --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield.js @@ -0,0 +1,52 @@ +// |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 <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/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/shell.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/shell.js diff --git a/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/this-val-not-async-generator.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/this-val-not-async-generator.js new file mode 100644 index 0000000000..243d28a96a --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/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-return +description: return rejects promise when `this` value is not an async generator +info: | + AsyncGenerator.prototype.return ( exception ) + 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 ) + ... + 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.return.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.return.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.return.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.return.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.return.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/return/this-val-not-object.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/this-val-not-object.js new file mode 100644 index 0000000000..977fa63a43 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/return/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-return +description: return rejects promise when `this` value not an object +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 ) + ... + 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.return.call(undefined).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.return should reject promise" + + " when `this` value `undefined`"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(undefined) expected TypeError but got " + e); + } + } + ), + AsyncGeneratorPrototype.return.call(1).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.return 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.return.call("string").then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.return 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.return.call(null).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.return should reject promise" + + " when `this` value `null`"); + }, + function (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("(null) expected TypeError but got " + e); + } + } + ), + AsyncGeneratorPrototype.return.call(true).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.return 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.return.call(symbol).then( + function () { + throw new Test262Error("AsyncGeneratorPrototype.return 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/shell.js b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/shell.js 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 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/browser.js 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 --- /dev/null +++ b/js/src/tests/test262/built-ins/AsyncGeneratorPrototype/throw/shell.js 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 <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/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 <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/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 <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/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 <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/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 <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/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 <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/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 <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/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 <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); |