summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Reflect/ownKeys.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_6/Reflect/ownKeys.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_6/Reflect/ownKeys.js')
-rw-r--r--js/src/tests/ecma_6/Reflect/ownKeys.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/Reflect/ownKeys.js b/js/src/tests/ecma_6/Reflect/ownKeys.js
new file mode 100644
index 000000000..5433562eb
--- /dev/null
+++ b/js/src/tests/ecma_6/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);