summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/spread-call-funapply.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/jit-test/tests/basic/spread-call-funapply.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/jit-test/tests/basic/spread-call-funapply.js')
-rw-r--r--js/src/jit-test/tests/basic/spread-call-funapply.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/spread-call-funapply.js b/js/src/jit-test/tests/basic/spread-call-funapply.js
new file mode 100644
index 000000000..9362d2a2d
--- /dev/null
+++ b/js/src/jit-test/tests/basic/spread-call-funapply.js
@@ -0,0 +1,88 @@
+load(libdir + "asserts.js");
+load(libdir + "eqArrayHelper.js");
+load(libdir + "iteration.js");
+
+function checkCommon(f) {
+ assertEqArray(f.apply(null, ...[[1, 2, 3]]), [1, 2, 3]);
+ assertEqArray(f.apply(...[null], [1, 2, 3]), [1, 2, 3]);
+ assertEqArray(f.apply(...[null], ...[[1, 2, 3]]), [1, 2, 3]);
+ assertEqArray(f.apply(...[null, [1, 2, 3]]), [1, 2, 3]);
+
+ // other iterable objects
+ assertEqArray(f.apply(...new Set([null, [1, 2, 3]])), [1, 2, 3]);
+ assertEqArray(f.apply(...[null, [1, 2, 3]][Symbol.iterator]()), [1, 2, 3]);
+ let itr = {};
+ itr[Symbol.iterator] = function() {
+ return {
+ i: 0,
+ next: function() {
+ this.i++;
+ if (this.i == 1)
+ return { value: null, done: false };
+ else if (this.i == 2)
+ return { value: [1, 2, 3], done: false };
+ else
+ return { value: undefined, done: true };
+ }
+ };
+ };
+ assertEqArray(f.apply(...itr), [1, 2, 3]);
+ function* gen() {
+ yield null;
+ yield [1, 2, 3];
+ }
+ assertEqArray(f.apply(...gen()), [1, 2, 3]);
+
+ let a;
+ assertEqArray(f.apply(null, ...a=[[1, 2, 3]]), [1, 2, 3]);
+
+ // 12.2.4.1.2 Runtime Semantics: ArrayAccumulation
+ // If Type(spreadObj) is not Object, then throw a TypeError exception.
+ assertThrowsInstanceOf(() => f.apply(null, ...null, [1, 2, 3]), TypeError);
+ assertThrowsInstanceOf(() => f.apply(null, ...undefined, [1, 2, 3]), TypeError);
+}
+
+function checkNormal(f) {
+ checkCommon(f);
+
+ assertEqArray(f.apply(null, ...[[]]), [undefined, undefined, undefined]);
+ assertEqArray(f.apply(null, ...[[1]]), [1, undefined, undefined]);
+ assertEqArray(f.apply(null, ...[[1, 2]]), [1, 2, undefined]);
+ assertEqArray(f.apply(null, ...[[1, 2, 3, 4]]), [1, 2, 3]);
+
+ assertEqArray(f.apply(null, ...[[undefined]]), [undefined, undefined, undefined]);
+}
+
+checkNormal(function(a, b, c) [a, b, c]);
+checkNormal((a, b, c) => [a, b, c]);
+
+function checkDefault(f) {
+ checkCommon(f);
+
+ assertEqArray(f.apply(null, ...[[]]), [-1, -2, -3]);
+ assertEqArray(f.apply(null, ...[[1]]), [1, -2, -3]);
+ assertEqArray(f.apply(null, ...[[1, 2]]), [1, 2, -3]);
+ assertEqArray(f.apply(null, ...[[1, 2, 3, 4]]), [1, 2, 3]);
+
+ assertEqArray(f.apply(null, ...[[undefined]]), [-1, -2, -3]);
+}
+
+checkDefault(function(a = -1, b = -2, c = -3) [a, b, c]);
+checkDefault((a = -1, b = -2, c = -3) => [a, b, c]);
+
+function checkRest(f) {
+ checkCommon(f);
+
+ assertEqArray(f.apply(null, ...[[]]), []);
+ assertEqArray(f.apply(null, ...[[1]]), [1]);
+ assertEqArray(f.apply(null, ...[[1, 2]]), [1, 2]);
+ assertEqArray(f.apply(null, ...[[1, 2, 3, 4]]), [1, 2, 3, 4]);
+
+ assertEqArray(f.apply(null, ...[[undefined]]), [undefined]);
+
+ // other iterable objects
+ assertEqArray(f.apply(null, ...new Map([[["a", "A"], ["b", "B"]]])).map(([k, v]) => k + v), ["aA", "bB"]);
+}
+
+checkRest(function(...x) x);
+checkRest((...x) => x);