| 1 |
// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
// file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 |
|
| 5 |
// https://bugzilla.mozilla.org/show_bug.cgi?id=782363 |
| 6 |
|
| 7 |
function assertSame(expected, actual) { |
| 8 |
if (expected !== actual) { |
| 9 |
throw "Expected '" + expected + "' but was '" + actual + "'"; |
| 10 |
} |
| 11 |
} |
| 12 |
|
| 13 |
function f1() { const a = 0; a++; return a; } |
| 14 |
function f2() { const a = 0; ++a; return a; } |
| 15 |
function f3() { const a = 0; return a++; } |
| 16 |
function f4() { const a = 0; return ++a; } |
| 17 |
function f5() { const a = 0; a--; return a; } |
| 18 |
function f6() { const a = 0; --a; return a; } |
| 19 |
function f7() { const a = 0; return a--; } |
| 20 |
function f8() { const a = 0; return --a; } |
| 21 |
|
| 22 |
var called = 0; |
| 23 |
var obj = {valueOf: function(){ called += 1; return 0 }}; |
| 24 |
function g1() { const a = obj; a++; return a; } |
| 25 |
function g2() { const a = obj; ++a; return a; } |
| 26 |
function g3() { const a = obj; return a++; } |
| 27 |
function g4() { const a = obj; return ++a; } |
| 28 |
function g5() { const a = obj; a--; return a; } |
| 29 |
function g6() { const a = obj; --a; return a; } |
| 30 |
function g7() { const a = obj; return a--; } |
| 31 |
function g8() { const a = obj; return --a; } |
| 32 |
|
| 33 |
assertSame(0, f1()); |
| 34 |
assertSame(0, f2()); |
| 35 |
assertSame(0, f3()); |
| 36 |
assertSame(1, f4()); |
| 37 |
assertSame(0, f5()); |
| 38 |
assertSame(0, f6()); |
| 39 |
assertSame(0, f7()); |
| 40 |
assertSame(-1, f8()); |
| 41 |
|
| 42 |
assertSame(obj, g1()); |
| 43 |
assertSame(obj, g2()); |
| 44 |
assertSame(obj, g3()); |
| 45 |
assertSame(1, g4()); |
| 46 |
assertSame(obj, g5()); |
| 47 |
assertSame(obj, g6()); |
| 48 |
assertSame(obj, g7()); |
| 49 |
assertSame(-1, g8()); |
| 50 |
|
| 51 |
assertSame(8, called); |
| 52 |
|
| 53 |
"success"; |