keith_miller@apple.com | bcc77f2 | 2016-07-15 06:03:25 +0000 | [diff] [blame] | 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.4.1.1 |
| 5 | description: > |
| 6 | Return IteratorClose(iter, status) if fail on adding value on constructing. |
| 7 | info: > |
| 8 | WeakSet ( [ iterable ] ) |
| 9 | |
| 10 | ... |
| 11 | 9. Repeat |
| 12 | f. Let status be Call(adder, set, «nextValue»). |
| 13 | g. If status is an abrupt completion, return IteratorClose(iter, status). |
| 14 | ---*/ |
| 15 | |
| 16 | var count = 0; |
| 17 | var iterable = {}; |
| 18 | iterable[Symbol.iterator] = function() { |
| 19 | return { |
| 20 | next: function() { |
| 21 | return { value: null, done: false }; |
| 22 | }, |
| 23 | return: function() { |
| 24 | count += 1; |
| 25 | } |
| 26 | }; |
| 27 | }; |
| 28 | WeakSet.prototype.add = function() { throw new Test262Error(); }; |
| 29 | |
| 30 | assert.throws(Test262Error, function() { |
| 31 | new WeakSet(iterable); |
| 32 | }); |
| 33 | |
| 34 | assert.sameValue( |
| 35 | count, 1, |
| 36 | 'The iterator is closed when `WeakSet.prototype.add` throws an error.' |
| 37 | ); |