Debian Codegraph @

js/src/tests/test262/language/statements/for-await-of/iterator-close-non-throw-get-method-abrupt.js

raw
1 // |reftest| async
2 // Copyright (C) 2020 Alexey Shvayka. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-asynciteratorclose
6 description: >
7 If retrieving an iterator's `return` method generates an error while
8 closing the iterator with non-throw completion, the error should be
9 forwarded to the runtime.
10 info: |
11 AsyncIteratorClose ( iteratorRecord, completion )
12
13 [...]
14 4. Let innerResult be GetMethod(iterator, "return").
15 5. If innerResult.[[Type]] is normal,
16 [...]
17 6. If completion.[[Type]] is throw, return Completion(completion).
18 7. If innerResult.[[Type]] is throw, return Completion(innerResult).
19
20 GetMethod ( V, P )
21
22 [...]
23 2. Let func be ? GetV(V, P).
24 features: [async-iteration]
25 flags: [async]
26 ---*/
27
28 const innerError = { name: "inner error" };
29 const asyncIterable = {};
30 asyncIterable[Symbol.asyncIterator] = function() {
31 return {
32 next: function() {
33 return { done: false, value: null };
34 },
35 get return() {
36 throw innerError;
37 },
38 };
39 };
40
41 let iterationCount = 0;
42 const promise = (async function() {
43 for await (const x of asyncIterable) {
44 iterationCount += 1;
45 break;
46 }
47 })();
48
49 promise.then(function(value) {
50 throw new Test262Error("Promise should be rejected, got: " + value);
51 }, function(error) {
52 assert.sameValue(error, innerError);
53 assert.sameValue(iterationCount, 1, "The loop body is evaluated");
54 }).then($DONE, $DONE);