Debian Codegraph @

js/src/tests/test262/language/statements/for-of/iterator-next-result-value-attr-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.g
5 description: >
6 If `nextValue` is an abrupt completion as per IteratorValue (ES6 7.4.4),
7 return the completion.
8 info: |
9 [...]
10 5. Repeat
11 a. Let nextResult be ? IteratorStep(iterator).
12 b. If nextResult is false, return NormalCompletion(V).
13 c. Let nextValue be ? IteratorValue(nextResult).
14 features: [Symbol.iterator]
15 ---*/
16
17 var iterable = {};
18 var iterationCount = 0;
19 var returnCount = 0;
20
21 iterable[Symbol.iterator] = function() {
22 return {
23 next: function() {
24 return {
25 done: false,
26 get value() {
27 throw new Test262Error();
28 }
29 };
30 },
31 return: function() {
32 returnCount += 1;
33 return {};
34 }
35 };
36 };
37
38 assert.throws(Test262Error, function() {
39 for (var x of iterable) {
40 iterationCount += 1;
41 }
42 });
43
44 assert.sameValue(iterationCount, 0, 'The loop body is not evaluated');
45 assert.sameValue(returnCount, 0, 'Iterator is not closed.');
46
47 reportCompare(0, 0);