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/entries.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/entries.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/js/src/tests/non262/object/entries.js b/js/src/tests/non262/object/entries.js new file mode 100644 index 0000000000..1a03ceb421 --- /dev/null +++ b/js/src/tests/non262/object/entries.js @@ -0,0 +1,94 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ + +if ("entries" in Object) { + assertEq(Object.entries.length, 1); + + var o, entries; + + o = { a: 3, b: 2 }; + entries = Object.entries(o); + assertDeepEq(entries, [["a", 3], ["b", 2]]); + + o = { get a() { return 17; }, b: 2 }; + entries = Object.entries(o), + assertDeepEq(entries, [["a", 17], ["b", 2]]); + + o = { __iterator__: function() { throw new Error("non-standard __iterator__ called?"); } }; + entries = Object.entries(o); + assertDeepEq(entries, [["__iterator__", o.__iterator__]]); + + o = { a: 1, b: 2 }; + delete o.a; + o.a = 3; + entries = Object.entries(o); + assertDeepEq(entries, [["b", 2], ["a", 3]]); + + o = [0, 1, 2]; + entries = Object.entries(o); + assertDeepEq(entries, [["0", 0], ["1", 1], ["2", 2]]); + + o = /./.exec("abc"); + entries = Object.entries(o); + assertDeepEq(entries, [["0", "a"], ["index", 0], ["input", "abc"], ["groups", undefined]]); + + o = { a: 1, b: 2, c: 3 }; + delete o.b; + o.b = 5; + entries = Object.entries(o); + assertDeepEq(entries, [["a", 1], ["c", 3], ["b", 5]]); + + function f() { } + f.prototype.p = 1; + o = new f(); + o.g = 1; + entries = Object.entries(o); + assertDeepEq(entries, [["g", 1]]); + + var o = {get a() {delete this.b; return 1}, b: 2, c: 3}; + entries = Object.entries(o); + assertDeepEq(entries, [["a", 1], ["c", 3]]); + + assertThrowsInstanceOf(() => Object.entries(), TypeError); + assertThrowsInstanceOf(() => Object.entries(undefined), TypeError); + assertThrowsInstanceOf(() => Object.entries(null), TypeError); + + assertDeepEq(Object.entries(1), []); + assertDeepEq(Object.entries(true), []); + if (typeof Symbol === "function") + assertDeepEq(Object.entries(Symbol("foo")), []); + + assertDeepEq(Object.entries("foo"), [["0", "f"], ["1", "o"], ["2", "o"]]); + + entries = Object.entries({ + get a(){ + Object.defineProperty(this, "b", {enumerable: false}); + return "A"; + }, + b: "B" + }); + assertDeepEq(entries, [["a", "A"]]); + + let ownKeysCallCount = 0; + let getOwnPropertyDescriptorCalls = []; + let target = { a: 1, b: 2, c: 3 }; + o = new Proxy(target, { + ownKeys() { + ownKeysCallCount++; + return ["c", "a"]; + }, + getOwnPropertyDescriptor(target, key) { + getOwnPropertyDescriptorCalls.push(key); + return Object.getOwnPropertyDescriptor(target, key); + } + }); + entries = Object.entries(o); + assertEq(ownKeysCallCount, 1); + assertDeepEq(entries, [["c", 3], ["a", 1]]); + assertDeepEq(getOwnPropertyDescriptorCalls, ["c", "a"]); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |