summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/lexical-environment/block-scoped-functions-deprecated-redecl.js
blob: af32be5d3db7218e651c875382871a0fff06dbdb (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
{
  assertEq(f(), 4);
  function f() { return 3; }
  assertEq(f(), 4);
  function f() { return 4; }
  assertEq(f(), 4);
}

// Annex B still works.
assertEq(f(), 4);

// The same thing with labels.
{
  assertEq(f(), 4);
  function f() { return 3; }
  assertEq(f(), 4);
  l: function f() { return 4; }
  assertEq(f(), 4);
}

// Annex B still works.
assertEq(f(), 4);

function test() {
  {
    assertEq(f(), 2);
    function f() { return 1; }
    assertEq(f(), 2);
    function f() { return 2; }
    assertEq(f(), 2);
  }

  // Annex B still works.
  assertEq(f(), 2);
}

test();

var log = '';

try {
  // Strict mode still cannot redeclare.
  eval(`"use strict";
  {
    function f() { }
    function f() { }
  }`);
} catch (e) {
  assertEq(e instanceof SyntaxError, true);
  log += 'e';
}

try {
  // Redeclaring an explicitly 'let'-declared binding doesn't work.
  eval(`{
    let x = 42;
    function x() {}
  }`);
} catch (e) {
  assertEq(e instanceof SyntaxError, true);
  log += 'e';
}

try {
  // Redeclaring an explicitly 'const'-declared binding doesn't work.
  eval(`{
    const x = 42;
    function x() {}
  }`);
} catch (e) {
  assertEq(e instanceof SyntaxError, true);
  log += 'e';
}

assertEq(log, 'eee');

if ('reportCompare' in this)
  reportCompare(true, true);