summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next')
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/absent-value-not-passed.js38
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-done.js53
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-value.js55
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-prototype.js43
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-rejected.js44
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-unwrap-promise.js44
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/return-promise.js28
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/shell.js113
9 files changed, 418 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/absent-value-not-passed.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/absent-value-not-passed.js
new file mode 100644
index 0000000000..ecba51e39c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/absent-value-not-passed.js
@@ -0,0 +1,38 @@
+// |reftest| async
+// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%asyncfromsynciteratorprototype%.next
+description: >
+ `next` method does not pass absent `value`.
+info: |
+ %AsyncFromSyncIteratorPrototype%.next ( value )
+
+ [...]
+ 5. If value is present, then
+ [...]
+ 6. Else,
+ a. Let result be IteratorNext(syncIteratorRecord).
+ [...]
+flags: [async]
+features: [async-iteration]
+includes: [asyncHelpers.js]
+---*/
+
+var nextArgumentsLength;
+var syncIterator = {
+ [Symbol.iterator]() {
+ return this;
+ },
+ next() {
+ nextArgumentsLength = arguments.length;
+ return {done: true};
+ },
+};
+
+asyncTest(async function () {
+ for await (let _ of syncIterator);
+
+ assert.sameValue(nextArgumentsLength, 0);
+});
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/browser.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/browser.js
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-done.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-done.js
new file mode 100644
index 0000000000..eb493bece9
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-done.js
@@ -0,0 +1,53 @@
+// |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-%asyncfromsynciteratorprototype%.next
+description: next() will reject promise if getter `done` abrupt completes
+info: |
+ %AsyncFromSyncIteratorPrototype%.next ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let nextResult be IteratorNext(syncIteratorRecord, value).
+ 6. IfAbruptRejectPromise(nextResult, promiseCapability).
+ 7. Let nextDone be IteratorComplete(nextResult).
+ 8. IfAbruptRejectPromise(nextDone, promiseCapability).
+ ...
+ 18. Return promiseCapability.[[Promise]].
+
+flags: [async]
+features: [async-iteration]
+---*/
+
+var thrownError = new Error("Catch me.");
+
+var obj = {
+ [Symbol.iterator]() {
+ return {
+ next() {
+ return {
+ get done() {
+ throw thrownError;
+ },
+ value: 1
+ }
+ }
+ };
+ }
+};
+
+async function* asyncg() {
+ yield* obj;
+}
+
+asyncg().next().then(
+ function (result) {
+ throw new Test262Error("Promise should be rejected.");
+ },
+ function (err) {
+ assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
+ }
+).then($DONE, $DONE);
+
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-value.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-value.js
new file mode 100644
index 0000000000..6a0e49439d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-value.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-%asyncfromsynciteratorprototype%.next
+description: next() will reject promise if getter `value` abrupt completes
+info: |
+ %AsyncFromSyncIteratorPrototype%.next ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let nextResult be IteratorNext(syncIteratorRecord, value).
+ 6. IfAbruptRejectPromise(nextResult, promiseCapability).
+ 7. Let nextDone be IteratorComplete(nextResult).
+ 8. If AbruptRejectPromise(nextDone, promiseCapability).
+ 9. Let nextValue be IteratorValue(nextResult).
+ 10. IfAbruptRejectPromise(nextValue, promiseCapability).
+ ...
+ 18. Return promiseCapability.[[Promise]].
+
+flags: [async]
+features: [async-iteration]
+---*/
+
+var thrownError = new Error("Catch me.");
+
+var obj = {
+ [Symbol.iterator]() {
+ return {
+ next() {
+ return {
+ get value() {
+ throw thrownError;
+ },
+ done: false
+ }
+ }
+ };
+ }
+};
+
+async function* asyncg() {
+ yield* obj;
+}
+
+asyncg().next().then(
+ function (result) {
+ throw new Test262Error("Promise should be rejected.");
+ },
+ function (err) {
+ assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
+ }
+).then($DONE, $DONE);
+
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-prototype.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-prototype.js
new file mode 100644
index 0000000000..d3f638e48e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-prototype.js
@@ -0,0 +1,43 @@
+// |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-%asyncfromsynciteratorprototype%.next
+description: next() returns a promise for an IteratorResult object
+info: |
+ %AsyncFromSyncIteratorPrototype%.next ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let nextResult be IteratorNext(syncIteratorRecord, value).
+ 6. IfAbruptRejectPromise(nextResult, promiseCapability).
+ 7. Let nextDone be IteratorComplete(nextResult).
+ 8. If AbruptRejectPromise(nextDone, promiseCapability).
+ 9. Let nextValue be IteratorValue(nextResult).
+ 10. IfAbruptRejectPromise(nextValue, promiseCapability).
+ ...
+ 14. Let steps be the algorithm steps defined in Async-from-Sync Iterator Value Unwrap Functions.
+
+ Async-from-Sync Iterator Value Unwrap Functions
+ 1. Return ! CreateIterResultObject(value, F.[[Done]]).
+
+flags: [async]
+features: [async-iteration]
+---*/
+
+function* g() {}
+
+async function* asyncg() {
+ yield* g();
+}
+
+asyncg().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/AsyncFromSyncIteratorPrototype/next/iterator-result-rejected.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-rejected.js
new file mode 100644
index 0000000000..8a5f9bf14a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-rejected.js
@@ -0,0 +1,44 @@
+// |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-%asyncfromsynciteratorprototype%.next
+description: next() will reject promise if sync iterator next() function returns an aburpt completion
+info: |
+ %AsyncFromSyncIteratorPrototype%.next ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let nextResult be IteratorNext(syncIteratorRecord, value).
+ 6. IfAbruptRejectPromise(nextResult, promiseCapability).
+ 7. Let nextDone be IteratorComplete(nextResult).
+ 8. If AbruptRejectPromise(nextDone, promiseCapability).
+ 9. Let nextValue be IteratorValue(nextResult).
+ 10. IfAbruptRejectPromise(nextValue, promiseCapability).
+ ...
+ 18. Return promiseCapability.[[Promise]].
+
+flags: [async]
+features: [async-iteration]
+---*/
+
+var thrownError = new Error("Catch me.");
+
+function* g() {
+ throw thrownError;
+}
+
+async function* asyncg() {
+ yield* g();
+}
+
+asyncg().next().then(
+ function (result) {
+ throw new Test262Error("Promise should be rejected.");
+ },
+ function (err) {
+ assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
+ }
+).then($DONE, $DONE);
+
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-unwrap-promise.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-unwrap-promise.js
new file mode 100644
index 0000000000..f77f3c2d96
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-unwrap-promise.js
@@ -0,0 +1,44 @@
+// |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-%asyncfromsynciteratorprototype%.next
+description: next() will unwrap a Promise value return by the sync iterator
+info: |
+ %AsyncFromSyncIteratorPrototype%.next ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let nextResult be IteratorNext(syncIteratorRecord, value).
+ 6. IfAbruptRejectPromise(nextResult, promiseCapability).
+ 7. Let nextDone be IteratorComplete(nextResult).
+ 8. If AbruptRejectPromise(nextDone, promiseCapability).
+ 9. Let nextValue be IteratorValue(nextResult).
+ 10. IfAbruptRejectPromise(nextValue, promiseCapability).
+ ...
+ 14. Let steps be the algorithm steps defined in Async-from-Sync Iterator Value Unwrap Functions.
+
+ Async-from-Sync Iterator Value Unwrap Functions
+ An async-from-sync iterator value unwrap function is an anonymous built-in
+ function that is used by methods of %AsyncFromSyncIteratorPrototype% when
+ processing the value field of an IteratorResult object, in order to wait for
+ its value if it is a promise and re-package the result in a new "unwrapped"
+ IteratorResult object. Each async iterator value unwrap function has a
+ [[Done]] internal slot.
+
+flags: [async]
+features: [async-iteration]
+---*/
+
+function* g() {
+ yield Promise.resolve(1);
+}
+
+async function* asyncg() {
+ yield* g();
+}
+
+asyncg().next().then(function (result) {
+ assert.sameValue(result.value, 1, "result.value should be unwrapped promise, got: " + result.value)
+}).then($DONE, $DONE);
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/return-promise.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/return-promise.js
new file mode 100644
index 0000000000..4f6a112c45
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/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-%asyncfromsynciteratorprototype%.next
+description: >
+ "next" returns a promise for an IteratorResult object
+info: |
+ %AsyncFromSyncIteratorPrototype%.next ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 18. Return promiseCapability.[[Promise]].
+
+features: [async-iteration]
+---*/
+
+function* g() {
+}
+
+async function* asyncg() {
+ yield* g();
+}
+
+var result = asyncg().next();
+assert(result instanceof Promise)
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/shell.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/next/shell.js
new file mode 100644
index 0000000000..ae18ad584d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/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);
+ }
+};