| 1 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 |
|
| 5 |
// Ensure function length is set correctly when a destructuring rest parameter |
| 6 |
// is present. |
| 7 |
|
| 8 |
assertEq(function(...[]) {}.length, 0); |
| 9 |
assertEq(function(...[a]) {}.length, 0); |
| 10 |
assertEq(function(...[a = 0]) {}.length, 0); |
| 11 |
assertEq(function(...{}) {}.length, 0); |
| 12 |
assertEq(function(...{p: a}) {}.length, 0); |
| 13 |
assertEq(function(...{p: a = 0}) {}.length, 0); |
| 14 |
assertEq(function(...{a = 0}) {}.length, 0); |
| 15 |
|
| 16 |
assertEq(function(x, ...[]) {}.length, 1); |
| 17 |
assertEq(function(x, ...[a]) {}.length, 1); |
| 18 |
assertEq(function(x, ...[a = 0]) {}.length, 1); |
| 19 |
assertEq(function(x, ...{}) {}.length, 1); |
| 20 |
assertEq(function(x, ...{p: a}) {}.length, 1); |
| 21 |
assertEq(function(x, ...{p: a = 0}) {}.length, 1); |
| 22 |
assertEq(function(x, ...{a = 0}) {}.length, 1); |
| 23 |
|
| 24 |
assertEq(function(x, y, ...[]) {}.length, 2); |
| 25 |
assertEq(function(x, y, ...[a]) {}.length, 2); |
| 26 |
assertEq(function(x, y, ...[a = 0]) {}.length, 2); |
| 27 |
assertEq(function(x, y, ...{}) {}.length, 2); |
| 28 |
assertEq(function(x, y, ...{p: a}) {}.length, 2); |
| 29 |
assertEq(function(x, y, ...{p: a = 0}) {}.length, 2); |
| 30 |
assertEq(function(x, y, ...{a = 0}) {}.length, 2); |
| 31 |
|
| 32 |
assertEq(function(x, y = 0, ...[]) {}.length, 1); |
| 33 |
assertEq(function(x, y = 0, ...[a]) {}.length, 1); |
| 34 |
assertEq(function(x, y = 0, ...[a = 0]) {}.length, 1); |
| 35 |
assertEq(function(x, y = 0, ...{}) {}.length, 1); |
| 36 |
assertEq(function(x, y = 0, ...{p: a}) {}.length, 1); |
| 37 |
assertEq(function(x, y = 0, ...{p: a = 0}) {}.length, 1); |
| 38 |
assertEq(function(x, y = 0, ...{a = 0}) {}.length, 1); |
| 39 |
|
| 40 |
if (typeof reportCompare === "function") |
| 41 |
reportCompare(0, 0); |