1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15assert((function([a], b, {c}) {}).length === 3); 16 17function f([a = "x", b = "y", c = "z"]) 18{ 19 assert(a === "a"); 20 assert(b === "b"); 21 assert(c === "z"); 22} 23f("ab") 24 25function g({ ["x" + "y"]: { a = 4, b = 5 }, }) 26{ 27 assert(a === 1); 28 assert(b === 5); 29} 30g({ xy: { a:1 } }); 31 32function h([,,a,,b,,]) 33{ 34 assert(a === 3); 35 assert(b === 5); 36} 37h([1,2,3,4,5,6,7,8]) 38 39function i([a] = [42], b = a) 40{ 41 assert(a === 42); 42 assert(b === 42); 43} 44i(); 45 46function j(a, [[b = a, [c] = [b], { d } = { d:eval("c") }], e = d + 1] = [[]]) 47{ 48 assert(a === 8); 49 assert(b === 8); 50 assert(c === 8); 51 assert(d === 8); 52 assert(e === 9); 53} 54j(8); 55 56function k([a = function() { return a; }]) 57{ 58 assert(typeof a === "function"); 59 assert(a() === a); 60} 61k([]); 62 63function l(a = 0, ...[b, c = 1, d = 4]) 64{ 65 assert(a === 1); 66 assert(b === 2); 67 assert(c === 3); 68 assert(d === 4); 69} 70l(1,2,3); 71 72Function("{a, x:b}","[c]", "{ 'dd':d, e = Math.cos(0)}", 73 "assert(a === 1);" + 74 "assert(b === undefined);" + 75 "assert(c === 3);" + 76 "assert(d === 4);" + 77 "assert(e === 1);" 78)({a:1, b:3}, [3], {a:1, b:2, dd:4}); 79 80function m() 81{ 82 var prop_name = "x"; 83 var def_val = 123; 84 85 function g({[prop_name]: a, b = def_val }) 86 { 87 assert(a === 12); 88 assert(b === 123); 89 } 90 91 g({ x:12 }) 92} 93m(); 94