set-iterator-close-after-add-failure.js (1186B)
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 esid: sec-set-constructor 5 description: > 6 Set ( [ iterable ] ) 7 8 When the Set function is called with optional argument iterable the following steps are taken: 9 10 ... 11 9. Repeat 12 a. Let next be IteratorStep(iter). 13 b. ReturnIfAbrupt(next). 14 c. If next is false, return set. 15 d. Let nextValue be IteratorValue(next). 16 e. ReturnIfAbrupt(nextValue). 17 f. Let status be Call(adder, set, «nextValue.[[value]]»). 18 g. If status is an abrupt completion, return IteratorClose(iter, status). 19 20 features: [Symbol.iterator] 21 ---*/ 22 23 var count = 0; 24 var iterable = {}; 25 iterable[Symbol.iterator] = function() { 26 return { 27 next: function() { 28 return { 29 value: null, 30 done: false 31 }; 32 }, 33 return: function() { 34 count += 1; 35 } 36 }; 37 }; 38 Set.prototype.add = function() { 39 throw new Error(); 40 } 41 42 assert.throws(Error, function() { 43 new Set(iterable); 44 }); 45 46 assert.sameValue( 47 count, 1, "The iterator is closed when `Set.prototype.add` throws an error." 48 ); 49 50 reportCompare(0, 0);