Debian Codegraph @

js/src/tests/test262/language/statements/for-of/iterator-close-non-object.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
5 description: >
6 If an iterator's `return` method returns a non-Object value, a TypeError
7 should be thrown.
8 features: [Symbol.iterator]
9 ---*/
10
11 var iterable = {};
12 var iterationCount = 0;
13
14 iterable[Symbol.iterator] = function() {
15 return {
16 next: function() {
17 return { done: false, value: null };
18 },
19 return: function() {
20 return 0;
21 }
22 };
23 };
24
25 assert.throws(TypeError, function() {
26 for (var x of iterable) {
27 iterationCount += 1;
28 break;
29 }
30 });
31
32 assert.sameValue(iterationCount, 1, 'The loop body is evaluated');
33
34 reportCompare(0, 0);