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-lazy-props.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-lazy-props.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/js/src/tests/non262/object/values-entries-lazy-props.js b/js/src/tests/non262/object/values-entries-lazy-props.js new file mode 100644 index 0000000000..0631c048af --- /dev/null +++ b/js/src/tests/non262/object/values-entries-lazy-props.js @@ -0,0 +1,93 @@ +// Return new objects for each test case. +function makeTestCases() { + // Call the resolve hook for arguments/string objects. + const resolveIndex = object => 0 in object; + + // Calls the resolve hook for functions. + const resolveFunction = object => "length" in object; + + const expected = array => ({ + keys: Object.keys(array), + values: Object.values(array), + entries: Object.entries(array), + }); + + return [ + // Mapped arguments objects. + { + object: function(){ return arguments; }(), + resolve: resolveIndex, + ...expected([]), + }, + { + object: function(x){ return arguments; }(1), + resolve: resolveIndex, + ...expected([1]), + }, + { + object: function(x, y, z){ return arguments; }(1, 2, 3), + resolve: resolveIndex, + ...expected([1, 2, 3]), + }, + + // Unmapped arguments objects. + { + object: function(){ "use strict"; return arguments; }(), + resolve: resolveIndex, + ...expected([]), + }, + { + object: function(x){ "use strict"; return arguments; }(1), + resolve: resolveIndex, + ...expected([1]), + }, + { + object: function(x, y, z){ "use strict"; return arguments; }(1, 2, 3), + resolve: resolveIndex, + ...expected([1, 2, 3]), + }, + + // String objects. + { object: new String(""), resolve: resolveIndex, ...expected([]), }, + { object: new String("a"), resolve: resolveIndex, ...expected(["a"]), }, + { object: new String("abc"), resolve: resolveIndex, ...expected(["a","b","c"]), }, + + // Function objects. + { object: function(){}, resolve: resolveFunction, ...expected([]), }, + ]; +} + +var assertWith = { + keys: assertEqArray, + values: assertEqArray, + entries(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 enumerate/resolve hooks. + +for (let method of ["keys", "values", "entries"]) { + let assert = assertWith[method]; + + // Call each method twice to test the case when + // - the enumerate hook wasn't yet called, + // - the enumerate hook was already called. + for (let {object, [method]: expected} of makeTestCases()) { + assert(Object[method](object), expected); + assert(Object[method](object), expected); + } + + // Test the case when enumerate wasn't yet called, but a property was already resolved. + for (let {object, resolve, [method]: expected} of makeTestCases()) { + resolve(object); // Call the resolve hook. + + assert(Object[method](object), expected); + assert(Object[method](object), expected); + } +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |