summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Object/fromEntries/uses-keys-not-iterator.js
blob: d9ec46e54b944ba4f822ffbceea3f0a860dd9dfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (C) 2018 Kevin Gibbons. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Reads properties rather than iterating.
esid: sec-object.fromentries
features: [Symbol.iterator, Object.fromEntries]
---*/

var iterable = {
  [Symbol.iterator]: function() {
    var count = 0;
    return {
      next: function() {
        if (count === 0) {
          ++count;
          return {
            done: false,
            value: {
              '0': 'first key',
              '1': 'first value',
              get [Symbol.iterator]() {
                throw new Test262Error('Object.fromEntries should not access Symbol.iterator on entry objects');
              },
            },
          };
        } else if (count === 1) {
          ++count;
          Array.prototype[Symbol.iterator] = function() {
            throw new Test262Error('Object.fromEntries should not access Symbol.iterator on entry arrays');
          };
          return {
            done: false,
            value: ['second key', 'second value'],
          };
        } else {
          return {
            done: true,
          };
        }
      },
    };
  },
};

var result = Object.fromEntries(iterable);
assert.sameValue(result['first key'], 'first value');
assert.sameValue(result['second key'], 'second value');

reportCompare(0, 0);