Debian Codegraph @

js/src/tests/non262/extensions/parse-rest-destructuring-parameter.js

raw
1 // |reftest| skip-if(!xulRuntime.shell)
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 function funArgs(params) {
7 return Reflect.parse(`function f(${params}) {}`).body[0].rest;
8 }
9
10 var arrayRest = funArgs("...[]");
11 assertEq(arrayRest.type, "ArrayPattern");
12 assertEq(arrayRest.elements.length, 0);
13
14 arrayRest = funArgs("...[a]");
15 assertEq(arrayRest.type, "ArrayPattern");
16 assertEq(arrayRest.elements.length, 1);
17
18 var objectRest = funArgs("...{}");
19 assertEq(objectRest.type, "ObjectPattern");
20 assertEq(objectRest.properties.length, 0);
21
22 objectRest = funArgs("...{p: a}");
23 assertEq(objectRest.type, "ObjectPattern");
24 assertEq(objectRest.properties.length, 1);
25
26 if (typeof reportCompare === "function")
27 reportCompare(0, 0);