summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/arguments/alias-function-closed.js
blob: 6c14ee78e77c586a4a372dfd7917cdc67666fd29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
function f1(a, aIs,        // without default parameter
            b=()=>62, bIs, // with default parameter
            // before function body
            c=(assertEq(a(), aIs), assertEq(b(), bIs),
               ()=>63),
            cIs) {
  // before function declarations
  assertEq(a(), 52);
  assertEq(b(), 53);
  assertEq(c(), 55);

  function a() {
    return 52;
  }
  function c() {
    return 54;
  }
  function g() {
    // close here
    assertEq(a(), 52); // after function declaration
    assertEq(b(), 53); // before function declaration
    assertEq(c(), 55); // before last function declaration
  }
  // function declaration after closed
  function b() {
    return 53;
  }

  assertEq(a(), 52); // after function declaration
  assertEq(b(), 53); // after function declaration
  assertEq(c(), 55); // before last function declaration

  g();
  c = ()=>72;
  assertEq(c(), 72); // after assignment in body
  h();
  assertEq(c(), 82); // after assignment in closed function

  function h() {
    assertEq(c(), 72); // after assignment in body
    c = ()=>82;
    assertEq(c(), 82); // after assignment in closed function
  }
  // function re-declaration after closed and assignment
  function c() {
    return 55;
  }
}
f1(()=>42, 42, undefined, 62, undefined, 63);
f1(()=>42, 42, undefined, 62, ()=>44, 44);
f1(()=>42, 42, ()=>43, 43, undefined, 63);
f1(()=>42, 42, ()=>43, 43, ()=>44, 44);

function f2(a, aIs,
            // call before body
            b=(function() { assertEq(a(), aIs); })(),
            // a inside body not accessible from defaults
            c=function() { assertEq(a(), 42); }) {
  function a() {
    return 52;
  }
  function g() {
    // close here
    assertEq(a(), 52);
  }

  assertEq(a(), 52);
  g();
  c();
}
f2(()=>42, 42);

function f3(a, aIs,
            // call before body
            // close here
            b=(function() { assertEq(a(), aIs); })(),
            // a inside body not accessible from defaults
            c=function() { assertEq(a(), 42); }) {
  function a() {
    return 52;
  }

  assertEq(a(), 52);
  c();
}
f3(()=>42, 42);

function f4(a,
            // assignment before body
            b=a=()=>62,
            c=(assertEq(a(), 62)),
            // eval in defaults exprs get own var envs
            d=eval("function a() { return 72; }"),
            e=(assertEq(a(), 62))) {
  function a() {
    return 52;
  }
  function g() {
    // close here
    assertEq(a(), 52);
  }

  assertEq(a(), 52);
  g();
}
f4(()=>42);

function f5(a, b, c, d) {
  // before var/function declarations
  assertEq(a(), 52);
  assertEq(b(), 53);
  assertEq(c(), 54);
  assertEq(d(), 55);

  function g() {
    // before var/function declarations, called after var declarations
    // close here
    assertEq(a(), 52);
    assertEq(b(), 63);
    assertEq(c(), 54);
    assertEq(d(), 65);
  }

  var a, b = ()=>63;
  var c, d = ()=>65;

  // after var declarations, before function declarations
  assertEq(a(), 52);
  assertEq(b(), 63);
  assertEq(c(), 54);
  assertEq(d(), 65);

  function h() {
    // after var declarations, before function declarations
    assertEq(a(), 52);
    assertEq(b(), 63);
    assertEq(c(), 54);
    assertEq(d(), 65);
  }
  function a() {
    return 52;
  }
  function b() {
    return 53;
  }
  function c() {
    return 54;
  }
  function d() {
    return 55;
  }
  function i() {
    // after var/function declarations
    assertEq(a(), 52);
    assertEq(b(), 63);
    assertEq(c(), 54);
    assertEq(d(), 65);
  }

  // after var/function declarations
  assertEq(a(), 52);
  assertEq(b(), 63);
  assertEq(c(), 54);
  assertEq(d(), 65);
  g();
  h();
  i();
}
f5(()=>42, ()=>43, ()=>44, ()=>45);