summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/rest-parameters
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/language/rest-parameters
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--js/src/tests/test262/language/rest-parameters/array-pattern.js51
-rw-r--r--js/src/tests/test262/language/rest-parameters/arrow-function.js19
-rw-r--r--js/src/tests/test262/language/rest-parameters/browser.js0
-rw-r--r--js/src/tests/test262/language/rest-parameters/expected-argument-count.js16
-rw-r--r--js/src/tests/test262/language/rest-parameters/no-alias-arguments.js17
-rw-r--r--js/src/tests/test262/language/rest-parameters/object-pattern.js46
-rw-r--r--js/src/tests/test262/language/rest-parameters/position-invalid.js14
-rw-r--r--js/src/tests/test262/language/rest-parameters/rest-index.js39
-rw-r--r--js/src/tests/test262/language/rest-parameters/rest-parameters-apply.js17
-rw-r--r--js/src/tests/test262/language/rest-parameters/rest-parameters-call.js16
-rw-r--r--js/src/tests/test262/language/rest-parameters/rest-parameters-produce-an-array.js14
-rw-r--r--js/src/tests/test262/language/rest-parameters/shell.js0
-rw-r--r--js/src/tests/test262/language/rest-parameters/with-new-target.js55
13 files changed, 304 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/rest-parameters/array-pattern.js b/js/src/tests/test262/language/rest-parameters/array-pattern.js
new file mode 100644
index 0000000000..4b7dbd969b
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/array-pattern.js
@@ -0,0 +1,51 @@
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-destructuring-binding-patterns
+description: >
+ The rest parameter can be a binding pattern.
+info: |
+ Destructuring Binding Patterns - Syntax
+
+ BindingRestElement[Yield]:
+ ...BindingPattern[?Yield]
+---*/
+
+function empty(...[]) {}
+
+function emptyWithArray(...[[]]) {}
+
+function emptyWithObject(...[{}]) {}
+
+function emptyWithRest(...[...[]]) {}
+
+function emptyWithLeading(x, ...[]) {}
+
+
+function singleElement(...[a]) {}
+
+function singleElementWithInitializer(...[a = 0]) {}
+
+function singleElementWithArray(...[[a]]) {}
+
+function singleElementWithObject(...[{p: q}]) {}
+
+function singleElementWithRest(...[...a]) {}
+
+function singleElementWithLeading(x, ...[a]) {}
+
+
+function multiElement(...[a, b, c]) {}
+
+function multiElementWithInitializer(...[a = 0, b, c = 1]) {}
+
+function multiElementWithArray(...[[a], b, [c]]) {}
+
+function multiElementWithObject(...[{p: q}, {r}, {s = 0}]) {}
+
+function multiElementWithRest(...[a, b, ...c]) {}
+
+function multiElementWithLeading(x, y, ...[a, b, c]) {}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/language/rest-parameters/arrow-function.js b/js/src/tests/test262/language/rest-parameters/arrow-function.js
new file mode 100644
index 0000000000..c06d76b9be
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/arrow-function.js
@@ -0,0 +1,19 @@
+// Copyright (C) 2014 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 14.1
+description: >
+ arrow functions
+includes: [compareArray.js]
+---*/
+var fn = (a, b, ...c) => c;
+
+assert.compareArray(fn(), []);
+assert.compareArray(fn(1, 2), []);
+assert.compareArray(fn(1, 2, 3), [3]);
+assert.compareArray(fn(1, 2, 3, 4), [3, 4]);
+assert.compareArray(fn(1, 2, 3, 4, 5), [3, 4, 5]);
+assert.compareArray(((...args) => args)(), []);
+assert.compareArray(((...args) => args)(1,2,3), [1,2,3]);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/language/rest-parameters/browser.js b/js/src/tests/test262/language/rest-parameters/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/browser.js
diff --git a/js/src/tests/test262/language/rest-parameters/expected-argument-count.js b/js/src/tests/test262/language/rest-parameters/expected-argument-count.js
new file mode 100644
index 0000000000..7d793b1080
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/expected-argument-count.js
@@ -0,0 +1,16 @@
+// Copyright (C) 2014 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 14.1.6
+description: >
+ The ExpectedArgumentCount of a FormalParameterList is the number of
+ FormalParameters to the left of either the rest parameter or the first
+ FormalParameter with an Initializer.
+---*/
+function af(...a) {}
+function bf(a, ...b) {}
+
+assert.sameValue(af.length, 0, "The value of `af.length` is `0`");
+assert.sameValue(bf.length, 1, "The value of `bf.length` is `1`");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/language/rest-parameters/no-alias-arguments.js b/js/src/tests/test262/language/rest-parameters/no-alias-arguments.js
new file mode 100644
index 0000000000..e89eb0f9b8
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/no-alias-arguments.js
@@ -0,0 +1,17 @@
+// Copyright (C) 2014 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 14.1
+description: >
+ no alias arguments
+includes: [compareArray.js]
+---*/
+function f(a, ...rest) {
+ arguments[0] = 1;
+ assert.sameValue(a, 3, "The value of `a` is `3`");
+ arguments[1] = 2;
+ assert.compareArray(rest, [4, 5]);
+}
+f(3, 4, 5);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/language/rest-parameters/object-pattern.js b/js/src/tests/test262/language/rest-parameters/object-pattern.js
new file mode 100644
index 0000000000..c7dd35236d
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/object-pattern.js
@@ -0,0 +1,46 @@
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-destructuring-binding-patterns
+description: >
+ The rest parameter can be a binding pattern.
+info: |
+ Destructuring Binding Patterns - Syntax
+
+ BindingRestElement[Yield]:
+ ...BindingPattern[?Yield]
+---*/
+
+function empty(...{}) {}
+
+function emptyWithArray(...{p: []}) {}
+
+function emptyWithObject(...{p: {}}) {}
+
+function emptyWithLeading(x, ...{}) {}
+
+
+function singleElement(...{a: b}) {}
+
+function singleElementWithInitializer(...{a: b = 0}) {}
+
+function singleElementWithArray(...{p: [a]}) {}
+
+function singleElementWithObject(...{p: {a: b}}) {}
+
+function singleElementWithLeading(x, ...{a: b}) {}
+
+
+function multiElement(...{a: r, b: s, c: t}) {}
+
+function multiElementWithInitializer(...{a: r = 0, b: s, c: t = 1}) {}
+
+function multiElementWithArray(...{p: [a], b, q: [c]}) {}
+
+function multiElementWithObject(...{a: {p: q}, b: {r}, c: {s = 0}}) {}
+
+function multiElementWithLeading(x, y, ...{a: r, b: s, c: t}) {}
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/language/rest-parameters/position-invalid.js b/js/src/tests/test262/language/rest-parameters/position-invalid.js
new file mode 100644
index 0000000000..1d57e18aab
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/position-invalid.js
@@ -0,0 +1,14 @@
+// |reftest| error:SyntaxError
+// Copyright (C) 2014 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 14.1
+description: >
+ Rest parameter cannot be followed by another named parameter
+negative:
+ phase: parse
+ type: SyntaxError
+---*/
+
+$DONOTEVALUATE();
+function f(a, ...b, c) {}
diff --git a/js/src/tests/test262/language/rest-parameters/rest-index.js b/js/src/tests/test262/language/rest-parameters/rest-index.js
new file mode 100644
index 0000000000..a1d7a0bafe
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/rest-index.js
@@ -0,0 +1,39 @@
+// Copyright (C) 2014 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 14.1
+description: >
+ rest index
+---*/
+assert.sameValue(
+ (function(...args) { return args.length; })(1,2,3,4,5),
+ 5,
+ "`(function(...args) { return args.length; })(1,2,3,4,5)` returns `5`"
+);
+assert.sameValue(
+ (function(a, ...args) { return args.length; })(1,2,3,4,5),
+ 4,
+ "`(function(a, ...args) { return args.length; })(1,2,3,4,5)` returns `4`"
+);
+assert.sameValue(
+ (function(a, b, ...args) { return args.length; })(1,2,3,4,5),
+ 3,
+ "`(function(a, b, ...args) { return args.length; })(1,2,3,4,5)` returns `3`"
+);
+assert.sameValue(
+ (function(a, b, c, ...args) { return args.length; })(1,2,3,4,5),
+ 2,
+ "`(function(a, b, c, ...args) { return args.length; })(1,2,3,4,5)` returns `2`"
+);
+assert.sameValue(
+ (function(a, b, c, d, ...args) { return args.length; })(1,2,3,4,5),
+ 1,
+ "`(function(a, b, c, d, ...args) { return args.length; })(1,2,3,4,5)` returns `1`"
+);
+assert.sameValue(
+ (function(a, b, c, d, e, ...args) { return args.length; })(1,2,3,4,5),
+ 0,
+ "`(function(a, b, c, d, e, ...args) { return args.length; })(1,2,3,4,5)` returns `0`"
+);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/language/rest-parameters/rest-parameters-apply.js b/js/src/tests/test262/language/rest-parameters/rest-parameters-apply.js
new file mode 100644
index 0000000000..4fe734ee4c
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/rest-parameters-apply.js
@@ -0,0 +1,17 @@
+// Copyright (C) 2014 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 14.1
+description: >
+ Rest parameter and Function.prototype.apply
+---*/
+function af(...a) {
+ return a.length;
+}
+
+assert.sameValue(af.apply(null, []), 0, "`af.apply(null, [])` returns `0`");
+assert.sameValue(af.apply(null, [1]), 1, "`af.apply(null, [1])` returns `1`");
+assert.sameValue(af.apply(null, [1, 2]), 2, "`af.apply(null, [1, 2])` returns `2`");
+assert.sameValue(af.apply(null, [1, ,2]), 3, "`af.apply(null, [1, ,2])` returns `3`");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/language/rest-parameters/rest-parameters-call.js b/js/src/tests/test262/language/rest-parameters/rest-parameters-call.js
new file mode 100644
index 0000000000..2d78024c4e
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/rest-parameters-call.js
@@ -0,0 +1,16 @@
+// Copyright (C) 2014 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 14.1
+description: >
+ Rest parameter and Function.prototype.call
+---*/
+function af(...a) {
+ return a.length;
+}
+
+assert.sameValue(af.call(null), 0, "`af.call(null)` returns `0`");
+assert.sameValue(af.call(null, 1), 1, "`af.call(null, 1)` returns `1`");
+assert.sameValue(af.call(null, 1, 2), 2, "`af.call(null, 1, 2)` returns `2`");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/language/rest-parameters/rest-parameters-produce-an-array.js b/js/src/tests/test262/language/rest-parameters/rest-parameters-produce-an-array.js
new file mode 100644
index 0000000000..5f99819574
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/rest-parameters-produce-an-array.js
@@ -0,0 +1,14 @@
+// Copyright (C) 2014 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 14.1
+description: >
+ Rest parameter produces an instance of Array
+---*/
+function af(...a) {
+ assert.sameValue(a.constructor, Array, "The value of `a.constructor` is `Array`");
+ assert(Array.isArray(a), "`Array.isArray(a)` returns `true`");
+}
+af(1);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/language/rest-parameters/shell.js b/js/src/tests/test262/language/rest-parameters/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/shell.js
diff --git a/js/src/tests/test262/language/rest-parameters/with-new-target.js b/js/src/tests/test262/language/rest-parameters/with-new-target.js
new file mode 100644
index 0000000000..c23fc938e7
--- /dev/null
+++ b/js/src/tests/test262/language/rest-parameters/with-new-target.js
@@ -0,0 +1,55 @@
+// Copyright (C) 2014 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 14.1
+description: >
+ with new target
+includes: [compareArray.js]
+---*/
+class Base {
+ constructor(...a) {
+ assert.sameValue(
+ arguments.length,
+ a.length,
+ "The value of `arguments.length` is `a.length`"
+ );
+ this.base = a;
+ var args = [];
+ for (var i = 0; i < arguments.length; ++i) {
+ args.push(arguments[i]);
+ }
+ assert.compareArray(args, a);
+ }
+}
+class Child extends Base {
+ constructor(...b) {
+ super(1, 2, 3);
+ assert.sameValue(
+ arguments.length,
+ b.length,
+ "The value of `arguments.length` is `b.length`"
+ );
+ this.child = b;
+ var args = [];
+ for (var i = 0; i < arguments.length; ++i) {
+ args.push(arguments[i]);
+ }
+ assert.compareArray(args, b);
+ }
+}
+
+var c = new Child(1, 2, 3);
+
+assert.sameValue(c.child.length, 3, "The value of `c.child.length` is `3`");
+assert.sameValue(c.base.length, 3, "The value of `c.base.length` is `3`");
+
+assert.compareArray(
+ c.child,
+ [1, 2, 3]
+);
+assert.compareArray(
+ c.base,
+ [1, 2, 3]
+);
+
+reportCompare(0, 0);