From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../built-ins/Object/fromEntries/browser.js | 0 .../built-ins/Object/fromEntries/empty-iterable.js | 21 ++++++ .../Object/fromEntries/evaluation-order.js | 84 ++++++++++++++++++++++ .../fromEntries/iterator-closed-for-null-entry.js | 59 +++++++++++++++ .../iterator-closed-for-string-entry.js | 59 +++++++++++++++ ...rator-closed-for-throwing-entry-key-accessor.js | 63 ++++++++++++++++ ...rator-closed-for-throwing-entry-key-tostring.js | 65 +++++++++++++++++ ...tor-closed-for-throwing-entry-value-accessor.js | 66 +++++++++++++++++ ...tor-not-closed-for-next-returning-non-object.js | 53 ++++++++++++++ ...erator-not-closed-for-throwing-done-accessor.js | 59 +++++++++++++++ .../iterator-not-closed-for-throwing-next.js | 54 ++++++++++++++ .../iterator-not-closed-for-uncallable-next.js | 44 ++++++++++++ .../built-ins/Object/fromEntries/key-order.js | 24 +++++++ .../test262/built-ins/Object/fromEntries/length.js | 18 +++++ .../test262/built-ins/Object/fromEntries/name.js | 18 +++++ .../Object/fromEntries/not-a-constructor.js | 31 ++++++++ .../built-ins/Object/fromEntries/prototype.js | 13 ++++ .../Object/fromEntries/requires-argument.js | 21 ++++++ .../test262/built-ins/Object/fromEntries/shell.js | 0 .../Object/fromEntries/simple-properties.js | 18 +++++ .../fromEntries/string-entry-object-succeeds.js | 13 ++++ .../fromEntries/string-entry-primitive-throws.js | 15 ++++ .../string-entry-string-object-succeeds.js | 13 ++++ .../Object/fromEntries/supports-symbols.js | 14 ++++ .../Object/fromEntries/to-property-key.js | 19 +++++ .../Object/fromEntries/uses-define-semantics.js | 22 ++++++ .../Object/fromEntries/uses-keys-not-iterator.js | 50 +++++++++++++ 27 files changed, 916 insertions(+) create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/browser.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/empty-iterable.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/evaluation-order.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-null-entry.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-string-entry.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-key-accessor.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-key-tostring.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-value-accessor.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-next-returning-non-object.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-throwing-done-accessor.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-throwing-next.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-uncallable-next.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/key-order.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/length.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/name.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/prototype.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/requires-argument.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/shell.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/simple-properties.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/string-entry-object-succeeds.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/string-entry-primitive-throws.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/string-entry-string-object-succeeds.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/supports-symbols.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/to-property-key.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/uses-define-semantics.js create mode 100644 js/src/tests/test262/built-ins/Object/fromEntries/uses-keys-not-iterator.js (limited to 'js/src/tests/test262/built-ins/Object/fromEntries') diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/browser.js b/js/src/tests/test262/built-ins/Object/fromEntries/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/empty-iterable.js b/js/src/tests/test262/built-ins/Object/fromEntries/empty-iterable.js new file mode 100644 index 0000000000..12dce89cac --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/empty-iterable.js @@ -0,0 +1,21 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.fromentries +description: When given an empty list, makes an empty object. +info: | + Object.fromEntries ( iterable ) + + ... + 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. + 5. Let adder be CreateBuiltinFunction(stepsDefine, « »). + 6. Return ? AddEntriesFromIterable(obj, iterable, adder). + +features: [Object.fromEntries] +---*/ + +var result = Object.fromEntries([]); +assert.sameValue(Object.keys(result).length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/evaluation-order.js b/js/src/tests/test262/built-ins/Object/fromEntries/evaluation-order.js new file mode 100644 index 0000000000..30677d6897 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/evaluation-order.js @@ -0,0 +1,84 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.fromentries +description: Evaluation order is iterator.next(), get '0', get '1', toPropertyKey, repeat. +info: | + Object.fromEntries ( iterable ) + + ... + 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. + 5. Let adder be CreateBuiltinFunction(stepsDefine, « »). + 6. Return ? AddEntriesFromIterable(obj, iterable, adder). + +includes: [compareArray.js] +features: [Symbol.iterator, Object.fromEntries] +---*/ + +var effects = []; + +function makeEntry(label) { + return { + get '0'() { + effects.push('access property "0" of ' + label + ' entry'); + return { + toString: function() { + effects.push('toString of ' + label + ' key'); + return label + ' key'; + }, + }; + }, + get '1'() { + effects.push('access property "1" of ' + label + ' entry'); + return label + ' value'; + }, + }; +} + +var iterable = { + [Symbol.iterator]: function() { + effects.push('get Symbol.iterator'); + var count = 0; + return { + next: function() { + effects.push('next ' + count); + if (count === 0) { + ++count; + return { + done: false, + value: makeEntry('first', 'first key', 'first value'), + }; + } else if (count === 1) { + ++count; + return { + done: false, + value: makeEntry('second', 'second key', 'second value'), + }; + } else { + return { + done: true, + }; + } + }, + }; + }, +}; + +var result = Object.fromEntries(iterable); +assert.compareArray(effects, [ + 'get Symbol.iterator', + 'next 0', + 'access property "0" of first entry', + 'access property "1" of first entry', + 'toString of first key', + 'next 1', + 'access property "0" of second entry', + 'access property "1" of second entry', + 'toString of second key', + 'next 2', +], 'Object.fromEntries evaluation order'); +assert.sameValue(result['first key'], 'first value'); +assert.sameValue(result['second key'], 'second value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-null-entry.js b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-null-entry.js new file mode 100644 index 0000000000..96afcb3735 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-null-entry.js @@ -0,0 +1,59 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.fromentries +description: Closes iterators when they return entries which are null. +info: | + Object.fromEntries ( iterable ) + + ... + 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. + 5. Let adder be CreateBuiltinFunction(stepsDefine, « »). + 6. Return ? AddEntriesFromIterable(obj, iterable, adder). + + AddEntriesFromIterable ( target, iterable, adder ) + + ... + 4. Repeat, + ... + d. If Type(nextItem) is not Object, then + i. Let error be ThrowCompletion(a newly created TypeError object). + ii. Return ? IteratorClose(iteratorRecord, error). + +features: [Symbol.iterator, Object.fromEntries] +---*/ + +var returned = false; +var iterable = { + [Symbol.iterator]: function() { + var advanced = false; + return { + next: function() { + if (advanced) { + throw new Test262Error('should only advance once'); + } + advanced = true; + return { + done: false, + value: null, + }; + }, + return: function() { + if (returned) { + throw new Test262Error('should only return once'); + } + returned = true; + }, + }; + }, +}; + +assert.sameValue(typeof Object.fromEntries, 'function'); +assert.throws(TypeError, function() { + Object.fromEntries(iterable); +}); + +assert(returned, 'iterator should be closed when entry is null'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-string-entry.js b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-string-entry.js new file mode 100644 index 0000000000..4f9639ac4a --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-string-entry.js @@ -0,0 +1,59 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.fromentries +description: Closes iterators when they return entries which are strings. +info: | + Object.fromEntries ( iterable ) + + ... + 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. + 5. Let adder be CreateBuiltinFunction(stepsDefine, « »). + 6. Return ? AddEntriesFromIterable(obj, iterable, adder). + + AddEntriesFromIterable ( target, iterable, adder ) + + ... + 4. Repeat, + ... + d. If Type(nextItem) is not Object, then + i. Let error be ThrowCompletion(a newly created TypeError object). + ii. Return ? IteratorClose(iteratorRecord, error). + +features: [Symbol.iterator, Object.fromEntries] +---*/ + +var returned = false; +var iterable = { + [Symbol.iterator]: function() { + var advanced = false; + return { + next: function() { + if (advanced) { + throw new Test262Error('should only advance once'); + } + advanced = true; + return { + done: false, + value: 'ab', + }; + }, + return: function() { + if (returned) { + throw new Test262Error('should only return once'); + } + returned = true; + }, + }; + }, +}; + +assert.sameValue(typeof Object.fromEntries, 'function'); +assert.throws(TypeError, function() { + Object.fromEntries(iterable); +}); + +assert(returned, 'iterator should be closed when entry is a string'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-key-accessor.js b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-key-accessor.js new file mode 100644 index 0000000000..c1b9e01880 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-key-accessor.js @@ -0,0 +1,63 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.fromentries +description: Closes iterators when accessing an entry's key throws. +info: | + Object.fromEntries ( iterable ) + + ... + 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. + 5. Let adder be CreateBuiltinFunction(stepsDefine, « »). + 6. Return ? AddEntriesFromIterable(obj, iterable, adder). + + AddEntriesFromIterable ( target, iterable, adder ) + + ... + 4. Repeat, + ... + e. Let k be Get(nextItem, "0"). + f. If k is an abrupt completion, return ? IteratorClose(iteratorRecord, k). + +features: [Symbol.iterator, Object.fromEntries] +---*/ + +function DummyError() {} + +var returned = false; +var iterable = { + [Symbol.iterator]: function() { + var advanced = false; + return { + next: function() { + if (advanced) { + throw new Test262Error('should only advance once'); + } + advanced = true; + return { + done: false, + value: { + get '0'() { + throw new DummyError(); + }, + }, + }; + }, + return: function() { + if (returned) { + throw new Test262Error('should only return once'); + } + returned = true; + }, + }; + }, +}; + +assert.throws(DummyError, function() { + Object.fromEntries(iterable); +}); + +assert(returned, 'iterator should be closed when entry property access throws'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-key-tostring.js b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-key-tostring.js new file mode 100644 index 0000000000..95b0e004bd --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-key-tostring.js @@ -0,0 +1,65 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.fromentries +description: Closes iterators when toString on a key throws. +info: | + Object.fromEntries ( iterable ) + + ... + 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. + 5. Let adder be CreateBuiltinFunction(stepsDefine, « »). + 6. Return ? AddEntriesFromIterable(obj, iterable, adder). + + AddEntriesFromIterable ( target, iterable, adder ) + + ... + 4. Repeat, + ... + e. Let k be Get(nextItem, "0"). + f. If k is an abrupt completion, return ? IteratorClose(iteratorRecord, k). + +features: [Symbol.iterator, Object.fromEntries] +---*/ + +function DummyError() {} + +var returned = false; +var iterable = { + [Symbol.iterator]: function() { + var advanced = false; + return { + next: function() { + if (advanced) { + throw new Test262Error('should only advance once'); + } + advanced = true; + return { + done: false, + value: { + 0: { + toString: function() { + throw new DummyError(); + }, + }, + }, + }; + }, + return: function() { + if (returned) { + throw new Test262Error('should only return once'); + } + returned = true; + }, + }; + }, +}; + +assert.throws(DummyError, function() { + Object.fromEntries(iterable); +}); + +assert(returned, 'iterator should be closed when key toString throws'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-value-accessor.js b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-value-accessor.js new file mode 100644 index 0000000000..3fc60197b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-closed-for-throwing-entry-value-accessor.js @@ -0,0 +1,66 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.fromentries +description: Closes iterators when accessing an entry's value throws. +info: | + Object.fromEntries ( iterable ) + + ... + 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. + 5. Let adder be CreateBuiltinFunction(stepsDefine, « »). + 6. Return ? AddEntriesFromIterable(obj, iterable, adder). + + AddEntriesFromIterable ( target, iterable, adder ) + + ... + 4. Repeat, + ... + g. Let v be Get(nextItem, "1"). + h. If v is an abrupt completion, return ? IteratorClose(iteratorRecord, v). + +features: [Symbol.iterator, Object.fromEntries] +---*/ + +function DummyError() {} + +var returned = false; +var iterable = { + [Symbol.iterator]: function() { + var advanced = false; + return { + next: function() { + if (advanced) { + throw new Test262Error('should only advance once'); + } + advanced = true; + return { + done: false, + value: { + get '0'() { + return 'key'; + }, + get '1'() { + throw new DummyError(); + }, + }, + }; + }, + return: function() { + if (returned) { + throw new Test262Error('should only return once'); + } + returned = true; + }, + }; + }, +}; + +assert.throws(DummyError, function() { + Object.fromEntries(iterable); +}); + +assert(returned, 'iterator should be closed when entry value property access throws'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-next-returning-non-object.js b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-next-returning-non-object.js new file mode 100644 index 0000000000..e4d37f5190 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-next-returning-non-object.js @@ -0,0 +1,53 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.fromentries +description: Does not close iterators with a `next` method which returns a non-object. +info: | + Object.fromEntries ( iterable ) + + ... + 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. + 5. Let adder be CreateBuiltinFunction(stepsDefine, « »). + 6. Return ? AddEntriesFromIterable(obj, iterable, adder). + + AddEntriesFromIterable ( target, iterable, adder ) + + ... + 4. Repeat, + a. Let next be ? IteratorStep(iteratorRecord). + + + IteratorStep ( iteratorRecord ) + + 1. Let result be ? IteratorNext(iteratorRecord). + + + IteratorNext ( iteratorRecord [ , value ] ) + + ... + 3. If Type(result) is not Object, throw a TypeError exception. + +features: [Symbol.iterator, Object.fromEntries] +---*/ + +var iterable = { + [Symbol.iterator]: function() { + return { + next: function() { + return null; + }, + return: function() { + throw new Test262Error('should not call return'); + }, + }; + }, +}; + +assert.sameValue(typeof Object.fromEntries, 'function'); +assert.throws(TypeError, function() { + Object.fromEntries(iterable); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-throwing-done-accessor.js b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-throwing-done-accessor.js new file mode 100644 index 0000000000..c88e496f85 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-throwing-done-accessor.js @@ -0,0 +1,59 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.fromentries +description: Does not close iterators with a `done` accessor which throws. +info: | + Object.fromEntries ( iterable ) + + ... + 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. + 5. Let adder be CreateBuiltinFunction(stepsDefine, « »). + 6. Return ? AddEntriesFromIterable(obj, iterable, adder). + + AddEntriesFromIterable ( target, iterable, adder ) + + ... + 4. Repeat, + a. Let next be ? IteratorStep(iteratorRecord). + + + IteratorStep ( iteratorRecord ) + + 1. Let result be ? IteratorNext(iteratorRecord). + + + IteratorNext ( iteratorRecord [ , value ] ) + + ... + 3. If Type(result) is not Object, throw a TypeError exception. + +features: [Symbol.iterator, Object.fromEntries] +---*/ + +function DummyError() {} + +var returned = false; +var iterable = { + [Symbol.iterator]: function() { + return { + next: function() { + return { + get done() { + throw new DummyError(); + }, + }; + }, + return: function() { + throw new Test262Error('should not call return'); + }, + }; + }, +}; + +assert.throws(DummyError, function() { + Object.fromEntries(iterable); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-throwing-next.js b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-throwing-next.js new file mode 100644 index 0000000000..386e4afc7c --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-throwing-next.js @@ -0,0 +1,54 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.fromentries +description: Does not close iterators with a `next` method which throws. +info: | + Object.fromEntries ( iterable ) + + ... + 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. + 5. Let adder be CreateBuiltinFunction(stepsDefine, « »). + 6. Return ? AddEntriesFromIterable(obj, iterable, adder). + + AddEntriesFromIterable ( target, iterable, adder ) + + ... + 4. Repeat, + a. Let next be ? IteratorStep(iteratorRecord). + + + IteratorStep ( iteratorRecord ) + + 1. Let result be ? IteratorNext(iteratorRecord). + + + IteratorNext ( iteratorRecord [ , value ] ) + + ... + 3. If Type(result) is not Object, throw a TypeError exception. + +features: [Symbol.iterator, Object.fromEntries] +---*/ + +function DummyError() {} + +var iterable = { + [Symbol.iterator]: function() { + return { + next: function() { + throw new DummyError(); + }, + return: function() { + throw new Test262Error('should not call return'); + }, + }; + }, +}; + +assert.throws(DummyError, function() { + Object.fromEntries(iterable); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-uncallable-next.js b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-uncallable-next.js new file mode 100644 index 0000000000..2d13a95735 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/iterator-not-closed-for-uncallable-next.js @@ -0,0 +1,44 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.fromentries +description: Does not close iterators with an uncallable `next` property. +info: | + Object.fromEntries ( iterable ) + + ... + 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. + 5. Let adder be CreateBuiltinFunction(stepsDefine, « »). + 6. Return ? AddEntriesFromIterable(obj, iterable, adder). + + AddEntriesFromIterable ( target, iterable, adder ) + + ... + 4. Repeat, + a. Let next be ? IteratorStep(iteratorRecord). + + + IteratorStep ( iteratorRecord ) + + 1. Let result be ? IteratorNext(iteratorRecord). +features: [Symbol.iterator, Object.fromEntries] +---*/ + +var iterable = { + [Symbol.iterator]: function() { + return { + next: null, + return: function() { + throw new Test262Error('should not call return'); + }, + }; + }, +}; + +assert.sameValue(typeof Object.fromEntries, 'function'); +assert.throws(TypeError, function() { + Object.fromEntries(iterable); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/key-order.js b/js/src/tests/test262/built-ins/Object/fromEntries/key-order.js new file mode 100644 index 0000000000..1a97611c13 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/key-order.js @@ -0,0 +1,24 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Key enumeration order of result objects matches the order of entries in the iterable. +esid: sec-object.fromentries +includes: [compareArray.js] +features: [Object.fromEntries] +---*/ + +var entries = [ + ['z', 1], + ['y', 2], + ['x', 3], + ['y', 4], +]; + +var result = Object.fromEntries(entries); +assert.sameValue(result.z, 1); +assert.sameValue(result.y, 4); +assert.sameValue(result.x, 3); +assert.compareArray(Object.getOwnPropertyNames(result), ['z', 'y', 'x']); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/length.js b/js/src/tests/test262/built-ins/Object/fromEntries/length.js new file mode 100644 index 0000000000..c510253b67 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/length.js @@ -0,0 +1,18 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.fromEntries.length is 1. +esid: sec-object.fromentries +includes: [propertyHelper.js] +features: [Object.fromEntries] +---*/ + +verifyProperty(Object.fromEntries, "length", { + value: 1, + enumerable: false, + writable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/name.js b/js/src/tests/test262/built-ins/Object/fromEntries/name.js new file mode 100644 index 0000000000..221c5a0e72 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/name.js @@ -0,0 +1,18 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Object.fromEntries.name is "fromEntries". +esid: sec-object.fromentries +includes: [propertyHelper.js] +features: [Object.fromEntries] +---*/ + +verifyProperty(Object.fromEntries, "name", { + value: "fromEntries", + enumerable: false, + writable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/not-a-constructor.js b/js/src/tests/test262/built-ins/Object/fromEntries/not-a-constructor.js new file mode 100644 index 0000000000..d63a99663e --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/not-a-constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Object.fromEntries does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Object.fromEntries, arrow-function] +---*/ + +assert.sameValue(isConstructor(Object.fromEntries), false, 'isConstructor(Object.fromEntries) must return false'); + +assert.throws(TypeError, () => { + new Object.fromEntries([]); +}, '`new Object.fromEntries([])` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/prototype.js b/js/src/tests/test262/built-ins/Object/fromEntries/prototype.js new file mode 100644 index 0000000000..13d02c7193 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/prototype.js @@ -0,0 +1,13 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Created objects inherit from Object.prototype. +esid: sec-object.fromentries +features: [Object.fromEntries] +---*/ + +var result = Object.fromEntries([]); +assert.sameValue(Object.getPrototypeOf(result), Object.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/requires-argument.js b/js/src/tests/test262/built-ins/Object/fromEntries/requires-argument.js new file mode 100644 index 0000000000..60f9c325d3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/requires-argument.js @@ -0,0 +1,21 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.fromentries +description: Throws when called without an argument. +info: | + Object.fromEntries ( iterable ) + + 1. Perform ? RequireObjectCoercible(iterable). + ... + +features: [Object.fromEntries] +---*/ + +assert.sameValue(typeof Object.fromEntries, 'function'); +assert.throws(TypeError, function() { + Object.fromEntries(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/shell.js b/js/src/tests/test262/built-ins/Object/fromEntries/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/simple-properties.js b/js/src/tests/test262/built-ins/Object/fromEntries/simple-properties.js new file mode 100644 index 0000000000..431556a966 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/simple-properties.js @@ -0,0 +1,18 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Creates data properties which are enumerable, writable, and configurable. +esid: sec-object.fromentries +includes: [propertyHelper.js] +features: [Object.fromEntries] +---*/ + +var result = Object.fromEntries([['key', 'value']]); +verifyProperty(result, "key", { + enumerable: true, + writable: true, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/string-entry-object-succeeds.js b/js/src/tests/test262/built-ins/Object/fromEntries/string-entry-object-succeeds.js new file mode 100644 index 0000000000..3f6d86b103 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/string-entry-object-succeeds.js @@ -0,0 +1,13 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Succeeds when an entry object is a boxed string. +esid: sec-object.fromentries +features: [Object.fromEntries] +---*/ + +var result = Object.fromEntries([Object('ab')]); +assert.sameValue(result['a'], 'b'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/string-entry-primitive-throws.js b/js/src/tests/test262/built-ins/Object/fromEntries/string-entry-primitive-throws.js new file mode 100644 index 0000000000..3bb9999363 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/string-entry-primitive-throws.js @@ -0,0 +1,15 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Throws when an entry object is a primitive string. +esid: sec-object.fromentries +features: [Object.fromEntries] +---*/ + +assert.sameValue(typeof Object.fromEntries, 'function'); +assert.throws(TypeError, function() { + Object.fromEntries(['ab']); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/string-entry-string-object-succeeds.js b/js/src/tests/test262/built-ins/Object/fromEntries/string-entry-string-object-succeeds.js new file mode 100644 index 0000000000..91ec49b4b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/string-entry-string-object-succeeds.js @@ -0,0 +1,13 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Succeeds when an entry object is a boxed string. +esid: sec-object.fromentries +features: [Object.fromEntries] +---*/ + +var result = Object.fromEntries([new String('ab')]); +assert.sameValue(result['a'], 'b'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/supports-symbols.js b/js/src/tests/test262/built-ins/Object/fromEntries/supports-symbols.js new file mode 100644 index 0000000000..0d30f04c35 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/supports-symbols.js @@ -0,0 +1,14 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Allows symbol keys. +esid: sec-object.fromentries +features: [Symbol, Object.fromEntries] +---*/ + +var key = Symbol(); +var result = Object.fromEntries([[key, 'value']]); +assert.sameValue(result[key], 'value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/to-property-key.js b/js/src/tests/test262/built-ins/Object/fromEntries/to-property-key.js new file mode 100644 index 0000000000..539e052848 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/to-property-key.js @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Coerces keys to strings using ToPropertyKey. +esid: sec-object.fromentries +features: [Symbol.toPrimitive, Object.fromEntries] +---*/ + +var key = { + [Symbol.toPrimitive]: function(hint) { + assert.sameValue(hint, 'string'); + return 'key'; + }, +}; +var result = Object.fromEntries([[key, 'value']]); +assert.sameValue(result.key, 'value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/fromEntries/uses-define-semantics.js b/js/src/tests/test262/built-ins/Object/fromEntries/uses-define-semantics.js new file mode 100644 index 0000000000..ae34cf564f --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/fromEntries/uses-define-semantics.js @@ -0,0 +1,22 @@ +// Copyright (C) 2018 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Uses [[DefineOwnProperty]] rather than [[Set]]. +esid: sec-object.fromentries +features: [Object.fromEntries] +---*/ + +Object.defineProperty(Object.prototype, 'property', { + get: function() { + throw new Test262Error('should not trigger getter on Object.prototype'); + }, + set: function() { + throw new Test262Error('should not trigger setter on Object.prototype'); + }, +}); + +var result = Object.fromEntries([['property', 'value']]); +assert.sameValue(result['property'], 'value', ''); + +reportCompare(0, 0); 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); -- cgit v1.2.3