michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = "(none)"; michael@0: var summary = "Test let and order of operation issues"; michael@0: var actual, expect; michael@0: michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus(summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: var failed = false; michael@0: michael@0: function f1(x) michael@0: { michael@0: let (foo) { michael@0: // scope of lhs x includes rhs, so x is NaN here -- bug 344952 michael@0: let x = ++x; michael@0: return x; michael@0: } michael@0: } michael@0: michael@0: function f2(x) michael@0: { michael@0: let (foo) michael@0: { michael@0: // scope of lhs x includes rhs, so x is NaN here -- bug 344952 michael@0: let x = x++; michael@0: return x; michael@0: } michael@0: } michael@0: michael@0: function f3(x) michael@0: { michael@0: let (foo) michael@0: { michael@0: var q = x; michael@0: let (x = x++) michael@0: { michael@0: if (x != q) michael@0: throw "f3():\n" + michael@0: " expected: x == q\n" + michael@0: " actual: x != q " + michael@0: "(where x == " + x + ", q == " + q + ")\n"; michael@0: } michael@0: return x; michael@0: } michael@0: } michael@0: michael@0: function f4(x) michael@0: { michael@0: var y = 7; michael@0: let (y = x, x = 3) michael@0: { michael@0: var q = 7 + x; michael@0: } michael@0: return x + y + q; michael@0: } michael@0: michael@0: function f5(x) michael@0: { michael@0: var q = x++; michael@0: let (y = x, r = 17, m = 32) { michael@0: return function(code) michael@0: { michael@0: return eval(code); michael@0: }; michael@0: } michael@0: } michael@0: michael@0: function f6() { michael@0: let (foo) michael@0: { michael@0: var i=3; michael@0: for (let i=i;;) { if (i != 3) throw "f6(): fail 1"; i = 7; break; } michael@0: if (i != 3) throw "f6(): fail 2"; michael@0: } michael@0: } michael@0: michael@0: try michael@0: { michael@0: var rv = f1(5); michael@0: if (!isNaN(rv)) michael@0: throw "f1(5):\n" + michael@0: " expected: NaN\n" + michael@0: " actual: " + rv; michael@0: michael@0: rv = f2(5); michael@0: if (!isNaN(rv)) michael@0: throw "f2(5):\n" + michael@0: " expected: NaN\n" + michael@0: " actual: " + rv; michael@0: /* michael@0: rv = f3(8); michael@0: if (rv != 9) michael@0: throw "f3(8):\n" + michael@0: " expected: 9\n" + michael@0: " actual: " + rv; michael@0: */ michael@0: michael@0: rv = f4(13); michael@0: if (rv != 30) michael@0: throw "f4(13):\n" + michael@0: " expected: 30\n" + michael@0: " actual: " + rv; michael@0: michael@0: var fun = f5(2); michael@0: michael@0: rv = fun("q"); michael@0: if (rv != 2) michael@0: throw "fun('q'):\n" + michael@0: " expected: 2\n" + michael@0: " actual: " + rv; michael@0: michael@0: rv = fun("x"); michael@0: if (rv != 3) michael@0: throw "fun('x'):\n" + michael@0: " expected: 3\n" + michael@0: " actual: " + rv; michael@0: michael@0: rv = fun("y"); michael@0: if (rv != 3) michael@0: throw "fun('y'):\n" + michael@0: " expected: 3\n" + michael@0: " actual: " + rv; michael@0: michael@0: rv = fun("let (y = y) { y += 32; }; y"); michael@0: if (rv != 3) michael@0: throw "fun('let (y = y) { y += 32; }; y'):\n" + michael@0: " expected: 3\n" + michael@0: " actual: " + rv; michael@0: michael@0: /* michael@0: f6(); michael@0: */ michael@0: } michael@0: catch (e) michael@0: { michael@0: print(e.toSource()); michael@0: failed = e; michael@0: } michael@0: michael@0: expect = false; michael@0: actual = failed; michael@0: michael@0: reportCompare(expect, actual, summary);