summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/spread-call-length.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-length.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-length.js')
-rw-r--r--js/src/jit-test/tests/basic/spread-call-length.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/spread-call-length.js b/js/src/jit-test/tests/basic/spread-call-length.js
new file mode 100644
index 000000000..3356c913a
--- /dev/null
+++ b/js/src/jit-test/tests/basic/spread-call-length.js
@@ -0,0 +1,52 @@
+load(libdir + 'iteration.js');
+
+let makeCall = farg => Function("f", "arg", "return f(" + farg + ");");
+let makeFunCall = farg => Function("f", "arg", "return f.call(null, " + farg + ");");
+let makeNew = farg => Function("f", "arg", "return new f(" + farg + ").length;");
+
+function checkLength(f, makeFn) {
+ assertEq(makeFn("...[1, 2, 3]")(f), 3);
+ assertEq(makeFn("1, ...[2], 3")(f), 3);
+ assertEq(makeFn("1, ...[2], ...[3]")(f), 3);
+ assertEq(makeFn("1, ...[2, 3]")(f), 3);
+ assertEq(makeFn("1, ...[], 2, 3")(f), 3);
+
+ assertEq(makeFn("...[1]")(f), 1);
+ assertEq(makeFn("...[1, 2]")(f), 2);
+ assertEq(makeFn("...[1, 2, 3, 4]")(f), 4);
+ assertEq(makeFn("1, ...[2, 3, 4], 5")(f), 5);
+
+ assertEq(makeFn("...[undefined]")(f), 1);
+
+ // other iterable objects
+ assertEq(makeFn("...arg")(f, new Int32Array([1, 2, 3])), 3);
+ assertEq(makeFn("...arg")(f, "abc"), 3);
+ assertEq(makeFn("...arg")(f, [1, 2, 3][Symbol.iterator]()), 3);
+ assertEq(makeFn("...arg")(f, new Set([1, 2, 3])), 3);
+ assertEq(makeFn("...arg")(f, new Map([["a", "A"], ["b", "B"], ["c", "C"]])), 3);
+ let itr = {};
+ itr[Symbol.iterator] = function() {
+ return {
+ i: 1,
+ next: function() {
+ if (this.i < 4)
+ return { value: this.i++, done: false };
+ else
+ return { value: undefined, done: true };
+ }
+ };
+ }
+ assertEq(makeFn("...arg")(f, itr), 3);
+ function* gen() {
+ for (let i = 1; i < 4; i ++)
+ yield i;
+ }
+ assertEq(makeFn("...arg")(f, gen()), 3);
+}
+
+checkLength(function(x) arguments.length, makeCall);
+checkLength(function(x) arguments.length, makeFunCall);
+function lengthClass(x) {
+ this.length = arguments.length;
+}
+checkLength(lengthClass, makeNew);