tor-browser

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

uses-keys-not-iterator.js (1379B)


      1 // Copyright (C) 2018 Kevin Gibbons. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: Reads properties rather than iterating.
      6 esid: sec-object.fromentries
      7 features: [Symbol.iterator, Object.fromEntries]
      8 ---*/
      9 
     10 var iterable = {
     11  [Symbol.iterator]: function() {
     12    var count = 0;
     13    return {
     14      next: function() {
     15        if (count === 0) {
     16          ++count;
     17          return {
     18            done: false,
     19            value: {
     20              '0': 'first key',
     21              '1': 'first value',
     22              get [Symbol.iterator]() {
     23                throw new Test262Error('Object.fromEntries should not access Symbol.iterator on entry objects');
     24              },
     25            },
     26          };
     27        } else if (count === 1) {
     28          ++count;
     29          Array.prototype[Symbol.iterator] = function() {
     30            throw new Test262Error('Object.fromEntries should not access Symbol.iterator on entry arrays');
     31          };
     32          return {
     33            done: false,
     34            value: ['second key', 'second value'],
     35          };
     36        } else {
     37          return {
     38            done: true,
     39          };
     40        }
     41      },
     42    };
     43  },
     44 };
     45 
     46 var result = Object.fromEntries(iterable);
     47 assert.sameValue(result['first key'], 'first value');
     48 assert.sameValue(result['second key'], 'second value');
     49 
     50 reportCompare(0, 0);