| 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: 23.1.1.1 |
| 5 |
description: > |
| 6 |
Closes the iterator after `not Object` error. |
| 7 |
info: | |
| 8 |
Map ( [ iterable ] ) |
| 9 |
|
| 10 |
... |
| 11 |
9. Repeat |
| 12 |
... |
| 13 |
d. Let nextItem be IteratorValue(next). |
| 14 |
e. ReturnIfAbrupt(nextItem). |
| 15 |
f. If Type(nextItem) is not Object, |
| 16 |
i. Let error be Completion{[[type]]: throw, [[value]]: a newly created |
| 17 |
TypeError object, [[target]]:empty}. |
| 18 |
ii. Return IteratorClose(iter, error). |
| 19 |
features: |
| 20 |
- Symbol |
| 21 |
- Symbol.iterator |
| 22 |
---*/ |
| 23 |
|
| 24 |
var count = 0; |
| 25 |
var nextItem; |
| 26 |
var iterable = {}; |
| 27 |
iterable[Symbol.iterator] = function() { |
| 28 |
return { |
| 29 |
next: function() { |
| 30 |
return { |
| 31 |
value: nextItem, |
| 32 |
done: false |
| 33 |
}; |
| 34 |
}, |
| 35 |
return: function() { |
| 36 |
count += 1; |
| 37 |
} |
| 38 |
}; |
| 39 |
}; |
| 40 |
|
| 41 |
nextItem = 1; |
| 42 |
assert.throws(TypeError, function() { |
| 43 |
new Map(iterable); |
| 44 |
}); |
| 45 |
assert.sameValue(count, 1); |
| 46 |
|
| 47 |
nextItem = true; |
| 48 |
assert.throws(TypeError, function() { |
| 49 |
new Map(iterable); |
| 50 |
}); |
| 51 |
assert.sameValue(count, 2); |
| 52 |
|
| 53 |
nextItem = ''; |
| 54 |
assert.throws(TypeError, function() { |
| 55 |
new Map(iterable); |
| 56 |
}); |
| 57 |
assert.sameValue(count, 3); |
| 58 |
|
| 59 |
nextItem = null; |
| 60 |
assert.throws(TypeError, function() { |
| 61 |
new Map(iterable); |
| 62 |
}); |
| 63 |
assert.sameValue(count, 4); |
| 64 |
|
| 65 |
nextItem = undefined; |
| 66 |
assert.throws(TypeError, function() { |
| 67 |
new Map(iterable); |
| 68 |
}); |
| 69 |
assert.sameValue(count, 5); |
| 70 |
|
| 71 |
nextItem = Symbol('a'); |
| 72 |
assert.throws(TypeError, function() { |
| 73 |
new Map(iterable); |
| 74 |
}); |
| 75 |
assert.sameValue(count, 6); |