| 1 |
// Tests annex B.3.5. |
| 2 |
|
| 3 |
assertThrowsInstanceOf(function () { |
| 4 |
eval(` |
| 5 |
function f() { |
| 6 |
let x; |
| 7 |
try {} catch (x) { |
| 8 |
var x; |
| 9 |
} |
| 10 |
} |
| 11 |
`); |
| 12 |
}, SyntaxError); |
| 13 |
|
| 14 |
assertThrowsInstanceOf(function () { |
| 15 |
eval(` |
| 16 |
function f() { |
| 17 |
try {} catch (x) { |
| 18 |
let y; |
| 19 |
var y; |
| 20 |
} |
| 21 |
} |
| 22 |
`); |
| 23 |
}, SyntaxError); |
| 24 |
|
| 25 |
assertThrowsInstanceOf(function () { |
| 26 |
eval(` |
| 27 |
function f() { |
| 28 |
try {} catch (x) { |
| 29 |
let x; |
| 30 |
} |
| 31 |
} |
| 32 |
`); |
| 33 |
}, SyntaxError); |
| 34 |
|
| 35 |
assertThrowsInstanceOf(function () { |
| 36 |
eval(` |
| 37 |
function f() { |
| 38 |
try {} catch (x) { |
| 39 |
const x; |
| 40 |
} |
| 41 |
} |
| 42 |
`); |
| 43 |
}, SyntaxError); |
| 44 |
|
| 45 |
// Tests that redeclaring a var inside the catch is not allowed if there's a |
| 46 |
// body-level lexical. |
| 47 |
assertThrowsInstanceOf(function () { |
| 48 |
eval(` |
| 49 |
let x; |
| 50 |
try {} catch (x) { |
| 51 |
var x; |
| 52 |
} |
| 53 |
`); |
| 54 |
}, SyntaxError); |
| 55 |
|
| 56 |
var log = ''; |
| 57 |
var x = 'global-x'; |
| 58 |
|
| 59 |
function g() { |
| 60 |
x = 'g'; |
| 61 |
try { throw 8; } catch (x) { |
| 62 |
var x = 42; |
| 63 |
log += x; |
| 64 |
} |
| 65 |
log += x; |
| 66 |
} |
| 67 |
g(); |
| 68 |
|
| 69 |
// Tests that var declaration is allowed in for-in head. |
| 70 |
function h0() { |
| 71 |
try {} catch (e) { |
| 72 |
for (var e in {}); |
| 73 |
} |
| 74 |
} |
| 75 |
h0(); |
| 76 |
|
| 77 |
// Tests that var declaration is allowed in C-for head. |
| 78 |
function h1() { |
| 79 |
try {} catch (e) { |
| 80 |
for (var e;;); |
| 81 |
} |
| 82 |
} |
| 83 |
h1(); |
| 84 |
|
| 85 |
// Tests that var declaration is allowed in for-of head. |
| 86 |
function h2() { |
| 87 |
try {} catch (e) { |
| 88 |
for (var e of {}); |
| 89 |
} |
| 90 |
} |
| 91 |
h2(); |
| 92 |
|
| 93 |
// Tests that redeclaring a var inside the catch is allowed. |
| 94 |
function h3() { |
| 95 |
var e; |
| 96 |
try {} catch (e) { |
| 97 |
var e; |
| 98 |
} |
| 99 |
} |
| 100 |
h3(); |
| 101 |
|
| 102 |
if (typeof evaluate === "function") { |
| 103 |
assertThrowsInstanceOf(function () { |
| 104 |
evaluate(` |
| 105 |
let y; |
| 106 |
try {} catch (y) { var y; } |
| 107 |
`); |
| 108 |
}, SyntaxError); |
| 109 |
} |
| 110 |
|
| 111 |
assertEq(log, "42g"); |
| 112 |
|
| 113 |
if ("reportCompare" in this) |
| 114 |
reportCompare(true, true) |