Debian Codegraph @

js/src/tests/test262/language/statements/for-of/iterator-close-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 throw completion, this error should be suppressed.
8 info: |
9 IteratorClose ( iteratorRecord, completion )
10
11 [...]
12 4. Let innerResult be GetMethod(iterator, "return").
13 5. If innerResult.[[Type]] is normal,
14 [...]
15 6. If completion.[[Type]] is throw, return Completion(completion).
16 7. If innerResult.[[Type]] is throw, return Completion(innerResult).
17
18 GetMethod ( V, P )
19
20 [...]
21 2. Let func be ? GetV(V, P).
22 3. If func is either undefined or null, return undefined.
23 4. If IsCallable(func) is false, throw a TypeError exception.
24 features: [Symbol.iterator]
25 ---*/
26
27 var iterable = {};
28 var iterationCount = 0;
29
30 iterable[Symbol.iterator] = function() {
31 return {
32 next: function() {
33 return { done: false, value: null };
34 },
35 return: 'str',
36 };
37 };
38
39 assert.throws(Test262Error, function() {
40 for (var x of iterable) {
41 iterationCount += 1;
42 throw new Test262Error('should not be overriden');
43 }
44 });
45
46 assert.sameValue(iterationCount, 1, 'The loop body is evaluated');
47
48 reportCompare(0, 0);