summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw')
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result-poisoned-done.js70
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result-poisoned-value.js70
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result-unwrap-promise.js66
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result.js60
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/poisoned-get-throw.js59
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/poisoned-throw.js61
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/result-object-error.js65
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/shell.js0
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-null.js60
-rw-r--r--js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-undefined.js54
11 files changed, 565 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/browser.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/browser.js
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result-poisoned-done.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result-poisoned-done.js
new file mode 100644
index 0000000000..bab1bf956d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result-poisoned-done.js
@@ -0,0 +1,70 @@
+// |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%.throw
+description: throw() will reject promise if getter `done` abrupt completes
+info: |
+ %AsyncFromSyncIteratorPrototype%.throw ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let throw be GetMethod(syncIterator, "throw").
+ ...
+ 8. Let throwResult be Call(throw, syncIterator, « value »).
+ ...
+ 11. Let throwDone be IteratorComplete(throwResult).
+ 12. IfAbruptRejectPromise(throwDone, promiseCapability).
+ 13. Let throwValue be IteratorValue(throwResult).
+ 14. IfAbruptRejectPromise(throwValue, promiseCapability).
+ ...
+ 20. Return promiseCapability.[[Promise]].
+
+flags: [async]
+features: [async-iteration]
+---*/
+
+var thrownError = new Error("Catch me.");
+
+var obj = {
+ [Symbol.iterator]() {
+ return {
+ next() {
+ return { value: 1, done: false };
+ },
+ throw() {
+ return {
+ get done() {
+ throw thrownError;
+ },
+ value: 1
+ };
+ }
+ };
+ }
+};
+
+async function* asyncg() {
+ yield* obj;
+}
+
+var iter = asyncg();
+
+iter.next().then(function(result) {
+
+ iter.throw().then(
+ function (result) {
+ throw new Test262Error("Promise should be rejected, got: " + result.value);
+ },
+ function (err) {
+ assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
+
+ iter.next().then(({ done, value }) => {
+ assert.sameValue(done, true, 'the iterator is completed');
+ assert.sameValue(value, undefined, 'value is undefined');
+ }).then($DONE, $DONE);
+ }
+ ).catch($DONE);
+
+}).catch($DONE);
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result-poisoned-value.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result-poisoned-value.js
new file mode 100644
index 0000000000..9745df52c1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result-poisoned-value.js
@@ -0,0 +1,70 @@
+// |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%.throw
+description: throw() will reject promise if getter `value` abrupt completes
+info: |
+ %AsyncFromSyncIteratorPrototype%.throw ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let throw be GetMethod(syncIterator, "throw").
+ ...
+ 8. Let throwResult be Call(throw, syncIterator, « value »).
+ ...
+ 11. Let throwDone be IteratorComplete(throwResult).
+ 12. IfAbruptRejectPromise(throwDone, promiseCapability).
+ 13. Let throwValue be IteratorValue(throwResult).
+ 14. IfAbruptRejectPromise(throwValue, promiseCapability).
+ ...
+ 20. Return promiseCapability.[[Promise]].
+
+flags: [async]
+features: [async-iteration]
+---*/
+
+var thrownError = new Error("Catch me.");
+
+var obj = {
+ [Symbol.iterator]() {
+ return {
+ next() {
+ return { value: 1, done: false };
+ },
+ throw() {
+ return {
+ get value() {
+ throw thrownError;
+ },
+ done: false
+ };
+ }
+ }
+ }
+};
+
+async function* asyncg() {
+ yield* obj;
+}
+
+var iter = asyncg();
+
+iter.next().then(function(result) {
+
+ iter.throw().then(
+ function (result) {
+ throw new Test262Error("Promise should be rejected, got: " + result.value);
+ },
+ function (err) {
+ assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
+
+ iter.next().then(({ done, value }) => {
+ assert.sameValue(done, true, 'the iterator is completed');
+ assert.sameValue(value, undefined, 'value is undefined');
+ }).then($DONE, $DONE);
+ }
+ ).catch($DONE);
+
+}).catch($DONE);
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result-unwrap-promise.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result-unwrap-promise.js
new file mode 100644
index 0000000000..9542254c75
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result-unwrap-promise.js
@@ -0,0 +1,66 @@
+// |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%.throw
+description: throw() will unwrap a Promise value return by the sync iterator
+info: |
+ %AsyncFromSyncIteratorPrototype%.throw ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let throw be GetMethod(syncIterator, "throw").
+ ...
+ 17. Let steps be the algorithm steps defined in Async-from-Sync Iterator Value Unwrap Functions.
+ ...
+ 20. Return promiseCapability.[[Promise]].
+
+ 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]
+---*/
+
+var thrownError = new Error("Don't catch me.")
+
+var obj = {
+ [Symbol.iterator]() {
+ return {
+ next() {
+ return { value: 1, done: false };
+ },
+ throw() {
+ return {
+ value: Promise.resolve(42),
+ done: true
+ };
+ }
+ };
+ }
+};
+
+async function* asyncg() {
+ return yield* obj;
+}
+
+let iter = asyncg();
+
+iter.next().then(function (result) {
+ iter.throw(thrownError).then(
+ function (result) {
+ assert.sameValue(result.value, 42, "Result.value should be unwrapped, got: " + result.value);
+
+ iter.next().then(({ done, value }) => {
+ assert.sameValue(done, true, 'the iterator is completed');
+ assert.sameValue(value, undefined, 'value is undefined');
+ }).then($DONE, $DONE);
+ }
+ ).catch($DONE);
+}).catch($DONE);
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result.js
new file mode 100644
index 0000000000..90b02da8c2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/iterator-result.js
@@ -0,0 +1,60 @@
+// |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%.throw
+description: throw() will call default sync throw
+info: |
+ %AsyncFromSyncIteratorPrototype%.throw ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let throw be GetMethod(syncIterator, "throw").
+ ...
+ 8. Let throwResult be Call(throw, syncIterator, « value »)
+ 9. IfAbruptRejectPromise(throwResult, promiseCapability).
+ ...
+ 22. Return promiseCapability.[[Promise]].
+
+ Generator.prototype.throw ( exception )
+ 1. Let g be the this value.
+ 2. Let C be Completion{[[Type]]: throw, [[Value]]: exception, [[Target]]: empty}.
+ 3. Return ? GeneratorResumeAbrupt(g, C).
+
+flags: [async]
+features: [async-iteration]
+---*/
+
+var thrownError = new Error("Catch me.")
+
+function* g() {
+ yield 42;
+ throw new Test262Error('throw closes iter');
+ yield 43;
+}
+
+async function* asyncg() {
+ yield* g();
+}
+
+var iter = asyncg();
+
+iter.next().then(function(result) {
+
+ // throw will call sync generator prototype built-in function throw
+ iter.throw(thrownError).then(
+ function(result) {
+ throw new Test262Error('throw should cause rejection of promise');
+ },
+ function(err) {
+ assert.sameValue(err, thrownError, "promise should be reject with custom error, got: " + err)
+
+ iter.next().then(({ done, value }) => {
+ assert.sameValue(done, true, 'the iterator is completed');
+ assert.sameValue(value, undefined, 'value is undefined');
+ }).then($DONE, $DONE);
+ }
+ ).catch($DONE);
+
+}).catch($DONE);
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/poisoned-get-throw.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/poisoned-get-throw.js
new file mode 100644
index 0000000000..5a87c2e2ba
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/poisoned-get-throw.js
@@ -0,0 +1,59 @@
+// |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%.throw
+description: throw() will return rejected promise if getter of `throw` abrupt completes
+info: |
+ %AsyncFromSyncIteratorPrototype%.return ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let return be GetMethod(syncIterator, "throw").
+ 6. IfAbruptRejectPromise(throw, promiseCapability).
+ ...
+ 22. Return promiseCapability.[[Promise]].
+
+flags: [async]
+features: [async-iteration]
+---*/
+
+var thrownError = new Error("Catch me.");
+
+var obj = {
+ [Symbol.iterator]() {
+ return {
+ next() {
+ return { value: 1, done: false };
+ },
+ get throw() {
+ throw thrownError;
+ }
+ };
+ }
+};
+
+async function* asyncg() {
+ yield* obj;
+}
+
+var iter = asyncg();
+
+iter.next().then(function(result) {
+
+ iter.throw().then(
+ function (result) {
+ throw new Test262Error("Promise should be rejected, got: " + result.value);
+ },
+ function (err) {
+ assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
+
+ iter.next().then(({ done, value }) => {
+ assert.sameValue(done, true, 'the iterator is completed');
+ assert.sameValue(value, undefined, 'value is undefined');
+ }).then($DONE, $DONE);
+ }
+ ).catch($DONE);
+
+}).catch($DONE);
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/poisoned-throw.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/poisoned-throw.js
new file mode 100644
index 0000000000..15656dbff8
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/poisoned-throw.js
@@ -0,0 +1,61 @@
+// |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%.throw
+description: throw() will return rejected promise if getter of `throw` abrupt completes
+info: |
+ %AsyncFromSyncIteratorPrototype%.throw ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let throw be GetMethod(syncIterator, "throw").
+ 6. IfAbruptRejectPromise(throw, promiseCapability).
+ ...
+ 8. Let throwResult be Call(throw, syncIterator, « value »).
+ 9. IfAbruptRejectPromise(throwResult, promiseCapability).
+ ...
+ 22. Return promiseCapability.[[Promise]].
+
+flags: [async]
+features: [async-iteration]
+---*/
+
+var thrownError = new Error("Catch me.");
+
+var obj = {
+ [Symbol.iterator]() {
+ return {
+ next() {
+ return { value: 1, done: false };
+ },
+ throw() {
+ throw thrownError;
+ }
+ };
+ }
+};
+
+async function* asyncg() {
+ yield* obj;
+}
+
+var iter = asyncg();
+
+iter.next().then(function(result) {
+
+ iter.throw().then(
+ function (result) {
+ throw new Test262Error("Promise should be rejected, got: " + result.value);
+ },
+ function (err) {
+ assert.sameValue(err, thrownError, "Promise should be rejected with thrown error");
+
+ iter.next().then(({ done, value }) => {
+ assert.sameValue(done, true, 'the iterator is completed');
+ assert.sameValue(value, undefined, 'value is undefined');
+ }).then($DONE, $DONE);
+ }
+ ).catch($DONE);
+}).catch($DONE);
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/result-object-error.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/result-object-error.js
new file mode 100644
index 0000000000..f59d06cc8a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/result-object-error.js
@@ -0,0 +1,65 @@
+// |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%.throw
+description: throw() will return rejected promise if getter of `throw` abrupt completes
+info: |
+ %AsyncFromSyncIteratorPrototype%.throw ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let throw be GetMethod(syncIterator, "throw").
+ 6. IfAbruptRejectPromise(thow, promiseCapability).
+ ...
+ 8. Let throwResult be Call(throw, syncIterator, « value »).
+ ...
+ 10. If Type(throwResult) is not Object,
+ a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a TypeError exception »).
+ b. Return promiseCapability.[[Promise]].
+
+flags: [async]
+features: [async-iteration]
+---*/
+
+var thrownError = new Error("Don't catch me.")
+
+var obj = {
+ [Symbol.iterator]() {
+ return {
+ next() {
+ return { value: 1, done: false };
+ },
+ throw() {
+ return 1;
+ }
+ };
+ }
+};
+
+async function* asyncg() {
+ yield* obj;
+}
+
+var iter = asyncg();
+
+iter.next().then(function(result) {
+
+ iter.throw(thrownError).then(
+ function (result) {
+ throw new Test262Error("Promise should be rejected, got: " + result.value);
+ },
+ function (err) {
+ let typeerror = err instanceof TypeError;
+ assert(typeerror, "Expect TypeError, got: " + err);
+
+ iter.next().then(({ done, value }) => {
+ assert.sameValue(done, true, 'the iterator is completed');
+ assert.sameValue(value, undefined, 'value is undefined');
+ }).then($DONE, $DONE);
+ }
+ ).catch($DONE);
+
+}).catch($DONE);
+
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/shell.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/shell.js
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-null.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-null.js
new file mode 100644
index 0000000000..9846e59b9a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-null.js
@@ -0,0 +1,60 @@
+// |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%.throw
+description: >
+ If syncIterator's "throw" method is `null`,
+ a Promise rejected with provided value is returned.
+info: |
+ %AsyncFromSyncIteratorPrototype%.throw ( value )
+
+ [...]
+ 5. Let throw be GetMethod(syncIterator, "throw").
+ [...]
+ 7. If throw is undefined, then
+ a. Perform ! Call(promiseCapability.[[Reject]], undefined, « value »).
+ b. Return promiseCapability.[[Promise]].
+
+ GetMethod ( V, P )
+
+ [...]
+ 2. Let func be ? GetV(V, P).
+ 3. If func is either undefined or null, return undefined.
+flags: [async]
+features: [async-iteration]
+---*/
+
+var throwGets = 0;
+var syncIterator = {
+ [Symbol.iterator]() {
+ return this;
+ },
+ next() {
+ return {value: 1, done: false};
+ },
+ get throw() {
+ throwGets += 1;
+ return null;
+ },
+};
+
+async function* asyncGenerator() {
+ yield* syncIterator;
+}
+
+var asyncIterator = asyncGenerator();
+var thrownError = { name: "err" };
+
+asyncIterator.next().then(function() {
+ return asyncIterator.throw(thrownError);
+}).then(function(result) {
+ throw new Test262Error("Promise should be rejected, got: " + result.value);
+}, function(err) {
+ assert.sameValue(err, thrownError);
+ return asyncIterator.next().then(function(result) {
+ assert.sameValue(result.value, undefined);
+ assert.sameValue(result.done, true);
+ });
+}).then($DONE, $DONE);
diff --git a/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-undefined.js b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-undefined.js
new file mode 100644
index 0000000000..a2f6c4c65f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-undefined.js
@@ -0,0 +1,54 @@
+// |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%.throw
+description: throw() will return rejected promise if sync `throw` undefined
+info: |
+ %AsyncFromSyncIteratorPrototype%.throw ( value )
+ ...
+ 2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ ...
+ 5. Let return be GetMethod(syncIterator, "throw").
+ 6. IfAbruptRejectPromise(throw, promiseCapability).
+ 7. If throw is undefined, then
+ a. Perform ! Call(promiseCapability.[[Reject]], undefined, « value »).
+ b. Return promiseCapability.[[Promise]].
+
+flags: [async]
+features: [async-iteration]
+---*/
+
+var obj = {
+ [Symbol.iterator]() {
+ return {
+ next() {
+ return { value: 1, done: false };
+ }
+ };
+ }
+};
+
+async function* asyncg() {
+ yield* obj;
+}
+
+var iter = asyncg();
+
+iter.next().then(function(result) {
+ iter.throw().then(
+ function (result) {
+ throw new Test262Error("Promise should be rejected, got: " + result.value);
+ },
+ function (err) {
+ assert.sameValue(err, undefined, "Promise should be rejected with undefined");
+
+ iter.next().then(({ done, value }) => {
+ assert.sameValue(done, true, 'the iterator is completed');
+ assert.sameValue(value, undefined, 'value is undefined');
+ }).then($DONE, $DONE);
+ }
+ ).catch($DONE);
+
+}).catch($DONE);