summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Reflect/propertyKeys.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Reflect/propertyKeys.js
parentInitial commit. (diff)
downloadfirefox-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/Reflect/propertyKeys.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/js/src/tests/non262/Reflect/propertyKeys.js b/js/src/tests/non262/Reflect/propertyKeys.js
new file mode 100644
index 0000000000..6495a96fd9
--- /dev/null
+++ b/js/src/tests/non262/Reflect/propertyKeys.js
@@ -0,0 +1,84 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/ */
+
+// Test corner cases involving Reflect methods' propertyKey arguments.
+
+// keys - Array of propertyKey values to be tested.
+//
+// Each element of this array is a record with these properties:
+//
+// * value: a value that will be passed as a property key
+// to the various Reflect methods;
+//
+// * expected: (optional) the string or symbol that ToPropertyKey(value)
+// should return. If this is omitted, ToPropertyKey(value) === value.
+//
+var keys = [
+ {value: null, expected: "null"},
+ {value: undefined, expected: "undefined"},
+ {value: true, expected: "true"},
+ {value: 42, expected: "42"},
+ {value: "string"},
+ {value: ""},
+ {value: "string with \0"},
+ {value: new String("ok"), expected: "ok"},
+ {value: Symbol("sym")},
+ {value: Symbol.iterator},
+ {value: Object(Symbol.for("comet")), expected: Symbol.for("comet")},
+ {
+ value: {
+ toString() { return "key"; },
+ valueOf() { return "bad"; }
+ },
+ expected: "key"
+ },
+ {
+ value: {
+ toString: undefined,
+ valueOf() { return "fallback"; }
+ },
+ expected: "fallback"
+ },
+ {
+ value: {
+ [Symbol.toPrimitive](hint) { return hint; }
+ },
+ expected: "string"
+ },
+ {
+ value: {
+ [Symbol.toPrimitive](hint) { return Symbol.for(hint); }
+ },
+ expected: Symbol.for("string")
+ }
+];
+
+for (var {value, expected} of keys) {
+ if (expected === undefined)
+ expected = value;
+
+ var obj = {};
+ assertEq(Reflect.defineProperty(obj, value, {value: 1, configurable: true}), true);
+ assertDeepEq(Reflect.ownKeys(obj), [expected]);
+ assertDeepEq(Reflect.getOwnPropertyDescriptor(obj, value),
+ {value: 1,
+ writable: false,
+ enumerable: false,
+ configurable: true});
+ assertEq(Reflect.deleteProperty(obj, value), true);
+ assertEq(Reflect.has(obj, value), false);
+ assertEq(Reflect.set(obj, value, 113), true);
+ assertEq(obj[expected], 113);
+ assertEq(Reflect.has(obj, value), true);
+ assertEq(Reflect.get(obj, value), 113);
+}
+
+// ToPropertyKey can throw.
+var exc = {};
+var badKey = {toString() { throw exc; }};
+var methodNames = ["defineProperty", "deleteProperty", "has", "get", "getOwnPropertyDescriptor", "set"];
+for (var name of methodNames) {
+ assertThrowsValue(() => Reflect[name]({}, badKey), exc);
+}
+
+reportCompare(0, 0);