• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15
16var g = -1;
17
18function f1() {
19  /* Function copied to var. */
20  assert (g === undefined);
21
22  {
23    assert (g() === 1);
24    function g() { return 1 };
25
26    {
27      assert (g() === 2);
28      function g() { return 2 };
29    }
30
31    assert (g() === 1);
32  }
33
34  assert (g() === 2);
35}
36f1();
37
38function f2() {
39  /* Function is not copied to var. */
40  'use strict'
41  assert (g === -1);
42
43  {
44    assert (g() === 1);
45    function g() { return 1 };
46
47    {
48      assert (g() === 2);
49      function g() { return 2 };
50    }
51
52    assert (g() === 1);
53  }
54
55  assert (g === -1);
56}
57f2();
58
59function f3() {
60  /* Function hoisted as let. */
61  assert (g === -1);
62
63  {
64    let g = 1;
65
66    {
67      if (true)
68      {
69        assert (g() === 2);
70
71        if (true)
72        {
73          assert (g() === 2);
74        }
75
76        function g() { return 2 };
77      }
78
79      assert (g === 1);
80    }
81
82    assert (g === 1);
83  }
84
85  assert (g === -1);
86}
87f3();
88