summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Array/from_proxy.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/Array/from_proxy.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/Array/from_proxy.js')
-rw-r--r--js/src/tests/ecma_6/Array/from_proxy.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/Array/from_proxy.js b/js/src/tests/ecma_6/Array/from_proxy.js
new file mode 100644
index 000000000..c3c82d0b7
--- /dev/null
+++ b/js/src/tests/ecma_6/Array/from_proxy.js
@@ -0,0 +1,55 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/ */
+
+// Two tests involving Array.from and a Proxy.
+var log = [];
+function LoggingProxy(target) {
+ var h = {
+ defineProperty: function (t, id) {
+ log.push("define", id);
+ return true;
+ },
+ has: function (t, id) {
+ log.push("has", id);
+ return id in t;
+ },
+ get: function (t, id) {
+ log.push("get", id);
+ return t[id];
+ },
+ set: function (t, id, v) {
+ log.push("set", id);
+ t[id] = v;
+ return true;
+ }
+ };
+ return new Proxy(target || [], h);
+}
+
+// When the new object created by Array.from is a Proxy,
+// Array.from calls handler.defineProperty to create new elements
+// but handler.set to set the length.
+LoggingProxy.from = Array.from;
+LoggingProxy.from([3, 4, 5]);
+assertDeepEq(log, ["define", "0", "define", "1", "define", "2", "set", "length"]);
+
+// When the argument passed to Array.from is a Proxy, Array.from
+// calls handler.get on it.
+log = [];
+assertDeepEq(Array.from(new LoggingProxy([3, 4, 5])), [3, 4, 5]);
+assertDeepEq(log, ["get", Symbol.iterator,
+ "get", "length", "get", "0",
+ "get", "length", "get", "1",
+ "get", "length", "get", "2",
+ "get", "length"]);
+
+// Array-like iteration only gets the length once.
+log = [];
+var arr = [5, 6, 7];
+arr[Symbol.iterator] = undefined;
+assertDeepEq(Array.from(new LoggingProxy(arr)), [5, 6, 7]);
+assertDeepEq(log, ["get", Symbol.iterator,
+ "get", "length", "get", "0", "get", "1", "get", "2"]);
+
+if (typeof reportCompare === 'function')
+ reportCompare(0, 0);