summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/statements/for-of/iterator-close-non-object.js
blob: 6d1f4a8ad90df15c9288d85474f970630769796e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4.13
description: >
    If an iterator's `return` method returns a non-Object value, a TypeError
    should be thrown.
features: [Symbol.iterator]
---*/

var iterable = {};
var iterationCount = 0;

iterable[Symbol.iterator] = function() {
  return {
    next: function() {
      return { done: false, value: null };
    },
    return: function() {
      return 0;
    }
  };
};

assert.throws(TypeError, function() {
  for (var x of iterable) {
    iterationCount += 1;
    break;
  }
});

assert.sameValue(iterationCount, 1, 'The loop body is evaluated');

reportCompare(0, 0);