Debian Codegraph @

js/src/tests/test262/language/statements/for-await-of/iterator-close-non-throw-get-method-non-callable.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 3. If func is either undefined or null, return undefined.
25 4. If IsCallable(func) is false, throw a TypeError exception.
26 features: [async-iteration]
27 flags: [async]
28 ---*/
29
30 const asyncIterable = {};
31 asyncIterable[Symbol.asyncIterator] = function() {
32 return {
33 next: function() {
34 return { done: false, value: null };
35 },
36 return: Symbol(),
37 };
38 };
39
40 let iterationCount = 0;
41 const promise = (async function() {
42 for await (const x of asyncIterable) {
43 iterationCount += 1;
44 break;
45 }
46 })();
47
48 promise.then(function(value) {
49 throw new Test262Error("Promise should be rejected, got: " + value);
50 }, function(error) {
51 assert.sameValue(error.constructor, TypeError);
52 assert.sameValue(iterationCount, 1, "The loop body is evaluated");
53 }).then($DONE, $DONE);