From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- js/src/tests/non262/Reflect/ownKeys.js | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 js/src/tests/non262/Reflect/ownKeys.js (limited to 'js/src/tests/non262/Reflect/ownKeys.js') diff --git a/js/src/tests/non262/Reflect/ownKeys.js b/js/src/tests/non262/Reflect/ownKeys.js new file mode 100644 index 0000000000..5433562eb5 --- /dev/null +++ b/js/src/tests/non262/Reflect/ownKeys.js @@ -0,0 +1,66 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ */ + +// Reflect.ownKeys(obj) returns an array of an object's own property keys. + +// Test that Reflect.ownKeys gets the expected result when applied to various +// objects. (These tests also check the basics: that the result is an array, +// that its prototype is correct, etc.) +var sym = Symbol.for("comet"); +var sym2 = Symbol.for("meteor"); +var cases = [ + {object: {z: 3, y: 2, x: 1}, + keys: ["z", "y", "x"]}, + {object: [], + keys: ["length"]}, + {object: new Int8Array(4), + keys: ["0", "1", "2", "3"]}, + {object: new Proxy({a: 7}, {}), + keys: ["a"]}, + {object: {[sym]: "ok"}, + keys: [sym]}, + {object: {[sym]: 0, // test 9.1.12 ordering + "str": 0, + "773": 0, + "0": 0, + [sym2]: 0, + "-1": 0, + "8": 0, + "second str": 0}, + keys: ["0", "8", "773", // indexes in numeric order + "str", "-1", "second str", // strings in insertion order + sym, sym2]}, // symbols in insertion order + {object: newGlobal().Math, // cross-compartment wrapper + keys: Reflect.ownKeys(Math)} +]; +for (var {object, keys} of cases) + assertDeepEq(Reflect.ownKeys(object), keys); + +// Reflect.ownKeys() creates a new array each time it is called. +var object = {}, keys = []; +for (var i = 0; i < 3; i++) { + var newKeys = Reflect.ownKeys(object); + assertEq(newKeys !== keys, true); + keys = newKeys; +} + +// Proxy behavior with successful ownKeys() handler +keys = ["str", "0"]; +obj = {}; +proxy = new Proxy(obj, { + ownKeys() { return keys; } +}); +var actual = Reflect.ownKeys(proxy); +assertDeepEq(actual, keys); // we get correct answers +assertEq(actual !== keys, true); // but not the same object + +// If a proxy breaks invariants, a TypeError is thrown. +var obj = Object.preventExtensions({}); +var proxy = new Proxy(obj, { + ownKeys() { return ["something"]; } +}); +assertThrowsInstanceOf(() => Reflect.ownKeys(proxy), TypeError); + +// For more Reflect.ownKeys tests, see target.js. + +reportCompare(0, 0); -- cgit v1.2.3