diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/object/values-entries-indexed.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/object/values-entries-indexed.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/js/src/tests/non262/object/values-entries-indexed.js b/js/src/tests/non262/object/values-entries-indexed.js new file mode 100644 index 0000000000..f4d801c272 --- /dev/null +++ b/js/src/tests/non262/object/values-entries-indexed.js @@ -0,0 +1,71 @@ +function assertSameEntries(actual, expected) { + assertEq(actual.length, expected.length); + for (let i = 0; i < expected.length; ++i) + assertEqArray(actual[i], expected[i]); +} + +// Test Object.keys/values/entries on objects with indexed properties. + +// Empty dense elements, test with array and plain object. +{ + let array = []; + assertEqArray(Object.keys(array), []); + assertEqArray(Object.values(array), []); + assertSameEntries(Object.entries(array), []); + + let object = {}; + assertEqArray(Object.keys(object), []); + assertEqArray(Object.values(object), []); + assertSameEntries(Object.entries(object), []); +} + +// Dense elements only, test with array and plain object. +{ + let array = [1, 2, 3]; + assertEqArray(Object.keys(array), ["0", "1", "2"]); + assertEqArray(Object.values(array), [1, 2, 3]); + assertSameEntries(Object.entries(array), [["0", 1], ["1", 2], ["2", 3]]); + + let object = {0: 4, 1: 5, 2: 6}; + assertEqArray(Object.keys(object), ["0", "1", "2"]); + assertEqArray(Object.values(object), [4, 5, 6]); + assertSameEntries(Object.entries(object), [["0", 4], ["1", 5], ["2", 6]]); +} + +// Extra indexed properties only, test with array and plain object. +{ + let array = []; + Object.defineProperty(array, 0, {configurable: true, enumerable: true, value: 123}); + + assertEqArray(Object.keys(array), ["0"]); + assertEqArray(Object.values(array), [123]); + assertSameEntries(Object.entries(array), [["0", 123]]); + + let object = []; + Object.defineProperty(object, 0, {configurable: true, enumerable: true, value: 123}); + + assertEqArray(Object.keys(object), ["0"]); + assertEqArray(Object.values(object), [123]); + assertSameEntries(Object.entries(object), [["0", 123]]); +} + +// Dense and extra indexed properties, test with array and plain object. +{ + let array = [1, 2, 3]; + Object.defineProperty(array, 0, {writable: false}); + + assertEqArray(Object.keys(array), ["0", "1", "2"]); + assertEqArray(Object.values(array), [1, 2, 3]); + assertSameEntries(Object.entries(array), [["0", 1], ["1", 2], ["2", 3]]); + + let object = {0: 4, 1: 5, 2: 6}; + Object.defineProperty(object, 0, {writable: false}); + + assertEqArray(Object.keys(object), ["0", "1", "2"]); + assertEqArray(Object.values(object), [4, 5, 6]); + assertSameEntries(Object.entries(object), [["0", 4], ["1", 5], ["2", 6]]); +} + + +if (typeof reportCompare === "function") + reportCompare(true, true); |