Debian Codegraph @

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

raw
1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-iteratorclose
5 description: >
6 If retrieving an iterator's `return` method generates an error while
7 closing the iterator with non-throw completion, the error should be
8 forwarded to the runtime.
9 info: |
10 IteratorClose ( iteratorRecord, completion )
11
12 [...]
13 4. Let innerResult be GetMethod(iterator, "return").
14 5. If innerResult.[[Type]] is normal,
15 [...]
16 6. If completion.[[Type]] is throw, return Completion(completion).
17 7. If innerResult.[[Type]] is throw, return Completion(innerResult).
18
19 GetMethod ( V, P )
20
21 [...]
22 2. Let func be ? GetV(V, P).
23 3. If func is either undefined or null, return undefined.
24 4. If IsCallable(func) is false, throw a TypeError exception.
25 features: [Symbol.iterator]
26 ---*/
27
28 var iterable = {};
29 var iterationCount = 0;
30
31 iterable[Symbol.iterator] = function() {
32 return {
33 next: function() {
34 return { done: false, value: null };
35 },
36 return: 1,
37 };
38 };
39
40 assert.throws(TypeError, function() {
41 for (var x of iterable) {
42 iterationCount += 1;
43 break;
44 }
45 });
46
47 assert.sameValue(iterationCount, 1, 'The loop body is evaluated');
48
49 reportCompare(0, 0);