| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
var gTestfile = 'order-of-operation.js'; |
| 7 |
|
| 8 |
var BUGNUMBER = "(none)"; |
| 9 |
var summary = "Test let and order of operation issues"; |
| 10 |
var actual, expect; |
| 11 |
|
| 12 |
printBugNumber(BUGNUMBER); |
| 13 |
printStatus(summary); |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
var failed = false; |
| 20 |
|
| 21 |
function f1(x) |
| 22 |
{ |
| 23 |
let (foo) { |
| 24 |
|
| 25 |
let x = ++x; |
| 26 |
return x; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
function f2(x) |
| 31 |
{ |
| 32 |
let (foo) |
| 33 |
{ |
| 34 |
|
| 35 |
let x = x++; |
| 36 |
return x; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
function f3(x) |
| 41 |
{ |
| 42 |
let (foo) |
| 43 |
{ |
| 44 |
var q = x; |
| 45 |
let (x = x++) |
| 46 |
{ |
| 47 |
if (x != q) |
| 48 |
throw "f3():\n" + |
| 49 |
" expected: x == q\n" + |
| 50 |
" actual: x != q " + |
| 51 |
"(where x == " + x + ", q == " + q + ")\n"; |
| 52 |
} |
| 53 |
return x; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
function f4(x) |
| 58 |
{ |
| 59 |
var y = 7; |
| 60 |
let (y = x, x = 3) |
| 61 |
{ |
| 62 |
var q = 7 + x; |
| 63 |
} |
| 64 |
return x + y + q; |
| 65 |
} |
| 66 |
|
| 67 |
function f5(x) |
| 68 |
{ |
| 69 |
var q = x++; |
| 70 |
let (y = x, r = 17, m = 32) { |
| 71 |
return function(code) |
| 72 |
{ |
| 73 |
return eval(code); |
| 74 |
}; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
function f6() { |
| 79 |
let (foo) |
| 80 |
{ |
| 81 |
var i=3; |
| 82 |
for (let i=i;;) { if (i != 3) throw "f6(): fail 1"; i = 7; break; } |
| 83 |
if (i != 3) throw "f6(): fail 2"; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
try |
| 88 |
{ |
| 89 |
var rv = f1(5); |
| 90 |
if (!isNaN(rv)) |
| 91 |
throw "f1(5):\n" + |
| 92 |
" expected: NaN\n" + |
| 93 |
" actual: " + rv; |
| 94 |
|
| 95 |
rv = f2(5); |
| 96 |
if (!isNaN(rv)) |
| 97 |
throw "f2(5):\n" + |
| 98 |
" expected: NaN\n" + |
| 99 |
" actual: " + rv; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
rv = f4(13); |
| 109 |
if (rv != 30) |
| 110 |
throw "f4(13):\n" + |
| 111 |
" expected: 30\n" + |
| 112 |
" actual: " + rv; |
| 113 |
|
| 114 |
var fun = f5(2); |
| 115 |
|
| 116 |
rv = fun("q"); |
| 117 |
if (rv != 2) |
| 118 |
throw "fun('q'):\n" + |
| 119 |
" expected: 2\n" + |
| 120 |
" actual: " + rv; |
| 121 |
|
| 122 |
rv = fun("x"); |
| 123 |
if (rv != 3) |
| 124 |
throw "fun('x'):\n" + |
| 125 |
" expected: 3\n" + |
| 126 |
" actual: " + rv; |
| 127 |
|
| 128 |
rv = fun("y"); |
| 129 |
if (rv != 3) |
| 130 |
throw "fun('y'):\n" + |
| 131 |
" expected: 3\n" + |
| 132 |
" actual: " + rv; |
| 133 |
|
| 134 |
rv = fun("let (y = y) { y += 32; }; y"); |
| 135 |
if (rv != 3) |
| 136 |
throw "fun('let (y = y) { y += 32; }; y'):\n" + |
| 137 |
" expected: 3\n" + |
| 138 |
" actual: " + rv; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
} |
| 144 |
catch (e) |
| 145 |
{ |
| 146 |
print(e.toSource()); |
| 147 |
failed = e; |
| 148 |
} |
| 149 |
|
| 150 |
expect = false; |
| 151 |
actual = failed; |
| 152 |
|
| 153 |
reportCompare(expect, actual, summary); |