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
15function must_throw (str, type = SyntaxError)
16{
17  try
18  {
19    eval (str);
20    assert (false);
21  }
22  catch (e)
23  {
24    assert (e instanceof type)
25  }
26}
27
28must_throw ("function f(a, [a]) {}");
29must_throw ("function f([a], a) {}");
30must_throw ("function f(a = b, [b]) {}; f()", ReferenceError);
31must_throw ("function f([a+b]) {}");
32must_throw ("function f([a().b]) {}");
33must_throw ("function f(...[a] = [1]) {}");
34
35function a1([a,b]) {
36  var a, b;
37
38  assert(a === 1);
39  assert(b === undefined);
40
41  var a = 3;
42  assert(a === 3);
43}
44a1([1]);
45
46function a2([a,b]) {
47  eval("var a, b");
48  assert(a === 1);
49  assert(b === undefined);
50
51  eval("var a = 3");
52  assert(a === 3);
53}
54a2([1]);
55
56function f1(a, [b], c, [d], e)
57{
58  assert (a === 1);
59  assert (b === 2);
60  assert (c === 3);
61  assert (d === 4);
62  assert (e === 5);
63}
64f1(1, [2], 3, [4], 5)
65
66function f2(a, [b], c, [d], e)
67{
68  eval("");
69  assert (a === 1);
70  assert (b === 2);
71  assert (c === 3);
72  assert (d === 4);
73  assert (e === 5);
74}
75f2(1, [2], 3, [4], 5)
76
77var g1 = (a, [b], c, [d], e) => {
78  assert (a === 1);
79  assert (b === 2);
80  assert (c === 3);
81  assert (d === 4);
82  assert (e === 5);
83}
84g1(1, [2], 3, [4], 5)
85
86var g2 = (a, [b], c, [d], e) => {
87  eval("");
88  assert (a === 1);
89  assert (b === 2);
90  assert (c === 3);
91  assert (d === 4);
92  assert (e === 5);
93}
94g2(1, [2], 3, [4], 5)
95