summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Object/fromEntries/uses-keys-not-iterator.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Object/fromEntries/uses-keys-not-iterator.js')
-rw-r--r--js/src/tests/test262/built-ins/Object/fromEntries/uses-keys-not-iterator.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/uses-keys-not-iterator.js b/js/src/tests/test262/built-ins/Object/fromEntries/uses-keys-not-iterator.js
new file mode 100644
index 0000000000..d9ec46e54b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Object/fromEntries/uses-keys-not-iterator.js
@@ -0,0 +1,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);