Debian Codegraph @

js/src/tests/test262/language/statements/for-of/iterator-close-throw-get-method-abrupt.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 features: [Symbol.iterator]
23 ---*/
24
25 var iterable = {};
26 var iterationCount = 0;
27
28 iterable[Symbol.iterator] = function() {
29 return {
30 next: function() {
31 return { done: false, value: null };
32 },
33 get return() {
34 throw { name: 'inner error' };
35 },
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);