tor-browser

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

iterable-with-object-keys.js (1579B)


      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-weakmap-iterable
      5 description: >
      6  Returns the new WeakMap adding entries from the iterable parameter, with
      7  Object keys.
      8 info: |
      9  WeakMap ( [ _iterable_ ] )
     10  5. Let _adder_ be ? Get(_map_, *"set"*).
     11  6. Return ? AddEntriesFromIterable(_map_, _iterable_, _adder_).
     12 
     13  AddEntriesFromIterable:
     14  3. Repeat,
     15    i. Let _status_ be Completion(Call(_adder_, _target_, « _k_, _v_ »)).
     16 
     17  WeakMap.prototype.set( _key_, _value_ ):
     18  6. Let _p_ be the Record {[[Key]]: _key_, [[Value]]: _value_}.
     19  7. Append _p_ as the last element of _entries_.
     20 features: [WeakMap]
     21 ---*/
     22 
     23 var first = {};
     24 var second = {};
     25 var results = [];
     26 var set = WeakMap.prototype.set;
     27 WeakMap.prototype.set = function(key, value) {
     28  results.push({
     29    _this: this,
     30    key: key,
     31    value: value
     32  });
     33  return set.call(this, key, value);
     34 };
     35 var map = new WeakMap([
     36  [first, 42],
     37  [second, 43]
     38 ]);
     39 
     40 assert.sameValue(results.length, 2, 'Called WeakMap#set for each object');
     41 assert.sameValue(results[0].key, first, 'Adds object in order - first key');
     42 assert.sameValue(results[0].value, 42, 'Adds object in order - first value');
     43 assert.sameValue(results[0]._this, map, 'Adds object in order - this');
     44 assert.sameValue(results[1].key, second, 'Adds object in order - second key');
     45 assert.sameValue(results[1].value, 43, 'Adds object in order - second value');
     46 assert.sameValue(results[1]._this, map, 'Adds object in order - this');
     47 
     48 reportCompare(0, 0);