Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | //----------------------------------------------------------------------------- |
michael@0 | 7 | var BUGNUMBER = "(none)"; |
michael@0 | 8 | var summary = "Test let and order of operation issues"; |
michael@0 | 9 | var actual, expect; |
michael@0 | 10 | |
michael@0 | 11 | printBugNumber(BUGNUMBER); |
michael@0 | 12 | printStatus(summary); |
michael@0 | 13 | |
michael@0 | 14 | /************** |
michael@0 | 15 | * BEGIN TEST * |
michael@0 | 16 | **************/ |
michael@0 | 17 | |
michael@0 | 18 | var failed = false; |
michael@0 | 19 | |
michael@0 | 20 | function f1(x) |
michael@0 | 21 | { |
michael@0 | 22 | let (foo) { |
michael@0 | 23 | // scope of lhs x includes rhs, so x is NaN here -- bug 344952 |
michael@0 | 24 | let x = ++x; |
michael@0 | 25 | return x; |
michael@0 | 26 | } |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function f2(x) |
michael@0 | 30 | { |
michael@0 | 31 | let (foo) |
michael@0 | 32 | { |
michael@0 | 33 | // scope of lhs x includes rhs, so x is NaN here -- bug 344952 |
michael@0 | 34 | let x = x++; |
michael@0 | 35 | return x; |
michael@0 | 36 | } |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function f3(x) |
michael@0 | 40 | { |
michael@0 | 41 | let (foo) |
michael@0 | 42 | { |
michael@0 | 43 | var q = x; |
michael@0 | 44 | let (x = x++) |
michael@0 | 45 | { |
michael@0 | 46 | if (x != q) |
michael@0 | 47 | throw "f3():\n" + |
michael@0 | 48 | " expected: x == q\n" + |
michael@0 | 49 | " actual: x != q " + |
michael@0 | 50 | "(where x == " + x + ", q == " + q + ")\n"; |
michael@0 | 51 | } |
michael@0 | 52 | return x; |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function f4(x) |
michael@0 | 57 | { |
michael@0 | 58 | var y = 7; |
michael@0 | 59 | let (y = x, x = 3) |
michael@0 | 60 | { |
michael@0 | 61 | var q = 7 + x; |
michael@0 | 62 | } |
michael@0 | 63 | return x + y + q; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function f5(x) |
michael@0 | 67 | { |
michael@0 | 68 | var q = x++; |
michael@0 | 69 | let (y = x, r = 17, m = 32) { |
michael@0 | 70 | return function(code) |
michael@0 | 71 | { |
michael@0 | 72 | return eval(code); |
michael@0 | 73 | }; |
michael@0 | 74 | } |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | function f6() { |
michael@0 | 78 | let (foo) |
michael@0 | 79 | { |
michael@0 | 80 | var i=3; |
michael@0 | 81 | for (let i=i;;) { if (i != 3) throw "f6(): fail 1"; i = 7; break; } |
michael@0 | 82 | if (i != 3) throw "f6(): fail 2"; |
michael@0 | 83 | } |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | try |
michael@0 | 87 | { |
michael@0 | 88 | var rv = f1(5); |
michael@0 | 89 | if (!isNaN(rv)) |
michael@0 | 90 | throw "f1(5):\n" + |
michael@0 | 91 | " expected: NaN\n" + |
michael@0 | 92 | " actual: " + rv; |
michael@0 | 93 | |
michael@0 | 94 | rv = f2(5); |
michael@0 | 95 | if (!isNaN(rv)) |
michael@0 | 96 | throw "f2(5):\n" + |
michael@0 | 97 | " expected: NaN\n" + |
michael@0 | 98 | " actual: " + rv; |
michael@0 | 99 | /* |
michael@0 | 100 | rv = f3(8); |
michael@0 | 101 | if (rv != 9) |
michael@0 | 102 | throw "f3(8):\n" + |
michael@0 | 103 | " expected: 9\n" + |
michael@0 | 104 | " actual: " + rv; |
michael@0 | 105 | */ |
michael@0 | 106 | |
michael@0 | 107 | rv = f4(13); |
michael@0 | 108 | if (rv != 30) |
michael@0 | 109 | throw "f4(13):\n" + |
michael@0 | 110 | " expected: 30\n" + |
michael@0 | 111 | " actual: " + rv; |
michael@0 | 112 | |
michael@0 | 113 | var fun = f5(2); |
michael@0 | 114 | |
michael@0 | 115 | rv = fun("q"); |
michael@0 | 116 | if (rv != 2) |
michael@0 | 117 | throw "fun('q'):\n" + |
michael@0 | 118 | " expected: 2\n" + |
michael@0 | 119 | " actual: " + rv; |
michael@0 | 120 | |
michael@0 | 121 | rv = fun("x"); |
michael@0 | 122 | if (rv != 3) |
michael@0 | 123 | throw "fun('x'):\n" + |
michael@0 | 124 | " expected: 3\n" + |
michael@0 | 125 | " actual: " + rv; |
michael@0 | 126 | |
michael@0 | 127 | rv = fun("y"); |
michael@0 | 128 | if (rv != 3) |
michael@0 | 129 | throw "fun('y'):\n" + |
michael@0 | 130 | " expected: 3\n" + |
michael@0 | 131 | " actual: " + rv; |
michael@0 | 132 | |
michael@0 | 133 | rv = fun("let (y = y) { y += 32; }; y"); |
michael@0 | 134 | if (rv != 3) |
michael@0 | 135 | throw "fun('let (y = y) { y += 32; }; y'):\n" + |
michael@0 | 136 | " expected: 3\n" + |
michael@0 | 137 | " actual: " + rv; |
michael@0 | 138 | |
michael@0 | 139 | /* |
michael@0 | 140 | f6(); |
michael@0 | 141 | */ |
michael@0 | 142 | } |
michael@0 | 143 | catch (e) |
michael@0 | 144 | { |
michael@0 | 145 | print(e.toSource()); |
michael@0 | 146 | failed = e; |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | expect = false; |
michael@0 | 150 | actual = failed; |
michael@0 | 151 | |
michael@0 | 152 | reportCompare(expect, actual, summary); |