summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Reflect/get.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/get.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/get.js')
-rw-r--r--js/src/tests/ecma_6/Reflect/get.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/Reflect/get.js b/js/src/tests/ecma_6/Reflect/get.js
new file mode 100644
index 000000000..b38b188b0
--- /dev/null
+++ b/js/src/tests/ecma_6/Reflect/get.js
@@ -0,0 +1,72 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/ */
+
+// Reflect.get gets the value of a property.
+
+var x = {p: 1};
+assertEq(Reflect.get(x, "p"), 1);
+assertEq(Reflect.get(x, "toString"), Object.prototype.toString);
+assertEq(Reflect.get(x, "missing"), undefined);
+
+
+// === Various targets
+
+// Array
+assertEq(Reflect.get([], 700), undefined);
+assertEq(Reflect.get(["zero", "one"], 1), "one");
+
+// TypedArray
+assertEq(Reflect.get(new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]), 7), 7);
+
+// Treatment of NaN
+var f = new Float64Array([NaN]);
+var u = new Uint32Array(f.buffer);
+u[0]++;
+u[1]++;
+assertEq(f[0], NaN);
+assertEq(Reflect.get(f, 0), NaN);
+
+// Proxy with no get handler
+assertEq(Reflect.get(new Proxy(x, {}), "p"), 1);
+
+// Proxy with a get handler
+var obj = new Proxy(x, {
+ get(t, k, r) { return k + "ful"; }
+});
+assertEq(Reflect.get(obj, "mood"), "moodful");
+
+// Exceptions thrown by a proxy's get handler are propagated.
+assertThrowsInstanceOf(() => Reflect.get(obj, Symbol()), TypeError);
+
+// Ordinary object, property has a setter and no getter
+obj = {set name(x) {}};
+assertEq(Reflect.get(obj, "name"), undefined);
+
+
+// === Receiver
+
+// Receiver argument is passed to getters as the this-value.
+obj = { get x() { return this; }};
+assertEq(Reflect.get(obj, "x", Math), Math);
+assertEq(Reflect.get(Object.create(obj), "x", JSON), JSON);
+
+// If missing, target is passed instead.
+assertEq(Reflect.get(obj, "x"), obj);
+
+// Receiver argument is passed to the proxy get handler.
+obj = new Proxy({}, {
+ get(t, k, r) {
+ assertEq(k, "itself");
+ return r;
+ }
+});
+assertEq(Reflect.get(obj, "itself"), obj);
+assertEq(Reflect.get(obj, "itself", Math), Math);
+assertEq(Reflect.get(Object.create(obj), "itself", Math), Math);
+
+// The receiver shouldn't have to be an object
+assertEq(Reflect.get(obj, "itself", 37.2), 37.2);
+
+// For more Reflect.get tests, see target.js and propertyKeys.js.
+
+reportCompare(0, 0);