tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

iterable-with-symbol-values.js (1177B)


      1 // |reftest| shell-option(--enable-symbols-as-weakmap-keys) skip-if(!xulRuntime.shell) -- requires shell-options
      2 // Copyright (C) 2022 Igalia, S.L. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 /*---
      5 esid: sec-weakset-iterable
      6 description: >
      7  Returns the new WeakSet adding Symbol values from the iterable parameter.
      8 info: |
      9  WeakSet ( [ _iterable_ ] )
     10  8. Repeat,
     11    d. Let _status_ be Completion(Call(_adder_, _set_, « _nextValue_ »)).
     12 
     13  WeakSet.prototype.add ( _value_ ):
     14  6. Append _value_ as the last element of _entries_.
     15 features: [Symbol, WeakSet, symbols-as-weakmap-keys]
     16 includes: [compareArray.js]
     17 ---*/
     18 
     19 var first = Symbol('a description');
     20 var second = Symbol('a description');
     21 var added = [];
     22 var realAdd = WeakSet.prototype.add;
     23 WeakSet.prototype.add = function(value) {
     24  added.push(value);
     25  return realAdd.call(this, value);
     26 };
     27 var s = new WeakSet([first, second, Symbol.hasInstance]);
     28 
     29 assert.compareArray(
     30  added,
     31  [first, second, Symbol.hasInstance],
     32  "add() was called 3 times, on the two unregistered and one well-known symbols in order"
     33 );
     34 
     35 WeakSet.prototype.add = realAdd;
     36 
     37 reportCompare(0, 0);