iterable-with-object-values.js (957B)
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-weakset-iterable 5 description: > 6 Returns the new WeakSet adding Object values from the iterable parameter. 7 info: | 8 WeakSet ( [ _iterable_ ] ) 9 8. Repeat, 10 d. Let _status_ be Completion(Call(_adder_, _set_, « _nextValue_ »)). 11 12 WeakSet.prototype.add ( _value_ ): 13 6. Append _value_ as the last element of _entries_. 14 features: [WeakSet] 15 ---*/ 16 17 var first = {}; 18 var second = {}; 19 var added = []; 20 var add = WeakSet.prototype.add; 21 WeakSet.prototype.add = function(value) { 22 added.push(value); 23 return add.call(this, value); 24 }; 25 var s = new WeakSet([first, second]); 26 27 assert.sameValue(added.length, 2, 'Called WeakSet#add for each object'); 28 assert.sameValue(added[0], first, 'Adds object in order - first'); 29 assert.sameValue(added[1], second, 'Adds object in order - second'); 30 31 reportCompare(0, 0);