1// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5
6(function testInFunctionDeclaration() {
7  var calls = 0;
8  function f() {
9    (() => {
10      calls++;
11      assertEquals(2, arguments.length);
12      assertEquals('a', arguments[0]);
13      assertEquals('b', arguments[1]);
14    })();
15  }
16  f('a', 'b');
17  assertEquals(1, calls);
18
19  calls = 0;
20  new f('a', 'b');
21  assertEquals(1, calls);
22})();
23
24
25(function testInFunctionExpression() {
26  var calls = 0;
27  var f = function() {
28    (() => {
29      calls++;
30      assertEquals(2, arguments.length);
31      assertEquals('a', arguments[0]);
32      assertEquals('b', arguments[1]);
33    })();
34  }
35  f('a', 'b');
36  assertEquals(1, calls);
37})();
38
39
40(function testInConstructor() {
41  'use strict';
42
43  var calls = 0;
44  class C {
45    constructor() {
46      (() => {
47        calls++;
48        assertEquals(2, arguments.length);
49        assertEquals('a', arguments[0]);
50        assertEquals('b', arguments[1]);
51      })();
52    }
53  }
54  new C('a', 'b');
55  assertEquals(1, calls);
56})();
57
58
59(function testInSetter() {
60  'use strict';
61
62  var calls = 0;
63  var o = {
64    set x(_) {
65      (() => {
66        calls++;
67        assertEquals(1, arguments.length);
68        assertEquals('a', arguments[0]);
69      })();
70    }
71  }
72  o.x = 'a';
73  assertEquals(1, calls);
74})();
75
76
77(function testMappedArguments() {
78  var calls = 0;
79  function f(x) {
80    x = 'c';
81    (() => {
82      calls++;
83      assertEquals(2, arguments.length);
84      assertEquals('c', arguments[0]);
85      x = 'a';
86      assertEquals('a', arguments[0]);
87      assertEquals('b', arguments[1]);
88    })();
89  }
90  f('a', 'b');
91  assertEquals(1, calls);
92})();
93
94
95(function testUnMappedArguments() {
96  'use strict';
97
98  var calls = 0;
99  function f(x) {
100    x = 'c';
101    (() => {
102      calls++;
103      assertEquals(2, arguments.length);
104      assertEquals('a', arguments[0]);
105      assertEquals('b', arguments[1]);
106    })();
107  }
108  f('a', 'b');
109  assertEquals(1, calls);
110})();
111
112
113(function testClosure() {
114  var calls = 0;
115  function f(x) {
116    return () => {
117      calls++;
118      assertEquals(2, arguments.length);
119      assertEquals('a', arguments[0]);
120      assertEquals('b', arguments[1]);
121    };
122  }
123  f('a', 'b')();
124  assertEquals(1, calls);
125})();
126
127
128(function testClosureMappedArguments() {
129  var calls = 0;
130  function f(x) {
131    x = 'c';
132    return () => {
133      calls++;
134      assertEquals(2, arguments.length);
135      assertEquals('c', arguments[0]);
136      x = 'a';
137      assertEquals('a', arguments[0]);
138      assertEquals('b', arguments[1]);
139    };
140  }
141  f('a', 'b')();
142  assertEquals(1, calls);
143})();
144
145
146(function testParamNamedArguments() {
147  var calls = 0;
148  function f(arguments) {
149    (() => {
150      calls++;
151      assertEquals('a', arguments);
152    })();
153  }
154  f('a');
155  assertEquals(1, calls);
156})();
157