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 f(a, b = a)
16{
17  function a() { return 2; }
18
19  assert(a() === 2);
20  assert(b === 1)
21}
22f(1);
23
24function g(a, b = a)
25{
26  function a() { return 2; }
27
28  eval("assert(a() === 2)");
29  eval("assert(b === 1)");
30}
31g(1);
32
33var x = 1;
34function h(a = x) {
35  assert(x === undefined);
36  var x = 2;
37  assert(a === 1);
38  assert(x === 2);
39}
40h();
41
42x = function() { return 4; }
43let y = 6;
44
45function i(a = x() / 2, b = (y) + 2, c = typeof z) {
46  let y = 10;
47  let z = 11;
48
49  function x() { return 5; }
50
51  assert(a === 2);
52  assert(x() === 5);
53  assert(b === 8);
54  assert(c === "undefined");
55  assert(y === 10);
56  assert(z === 11);
57}
58i();
59
60var arguments = 10;
61function j(a = arguments[1])
62{
63  assert(a === 2);
64  a = 3;
65  assert(arguments[0] === undefined)
66}
67j(undefined,2);
68
69function k(a = 2)
70{
71  let d = 5;
72  assert(d === 5);
73  eval("assert(a === 2)");
74}
75k();
76
77function l(a = 3)
78{
79  const d = 6;
80  assert(d === 6);
81  eval("assert(a === 3)");
82}
83l();
84
85function m(a, b = 2)
86{
87  assert(a === 1);
88  assert(arguments[0] === 1);
89  assert(b === 2);
90  assert(arguments[1] === undefined);
91
92  a = 8;
93  b = 9;
94
95  assert(a === 8);
96  assert(arguments[0] === 1);
97  assert(b === 9);
98  assert(arguments[1] === undefined);
99}
100m(1);
101