Debian Codegraph @

js/src/tests/test262/language/statements/for-of/iterator-next-error.js

raw
1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 es6id: 13.6.4.13 S5.d
5 description: >
6 If `nextResult` is an abrupt completion as per IteratorStep (ES6 7.4.5),
7 return the completion.
8 info: |
9 [...]
10 5. Repeat
11 a. Let nextResult be ? IteratorStep(iterator).
12 features: [Symbol.iterator]
13 ---*/
14
15 var iterable = {};
16 var iterationCount = 0;
17 var returnCount = 0;
18
19 iterable[Symbol.iterator] = function() {
20 return {
21 next: function() {
22 throw new Test262Error();
23 },
24 return: function() {
25 returnCount += 1;
26 return {};
27 }
28 };
29 };
30
31 assert.throws(Test262Error, function() {
32 for (var x of iterable) {
33 iterationCount += 1;
34 }
35 });
36
37 assert.sameValue(iterationCount, 0, 'The loop body is not evaluated');
38 assert.sameValue(returnCount, 0, 'Iterator is not closed.');
39
40 reportCompare(0, 0);