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 = "Order of destructuring, destructuring in the presence of " + michael@0: "exceptions"; 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: michael@0: var a = "FAILED", b = "PASSED"; michael@0: michael@0: function exceptObj() michael@0: { michael@0: return { get b() { throw "PASSED"; }, a: "PASSED" }; michael@0: } michael@0: michael@0: function partialEvalObj() michael@0: { michael@0: try michael@0: { michael@0: ({a:a, b:b}) = exceptObj(); michael@0: throw "FAILED"; michael@0: } michael@0: catch (ex) michael@0: { michael@0: if (ex !== "PASSED") michael@0: throw "bad exception thrown: " + ex; michael@0: } michael@0: } michael@0: michael@0: michael@0: var c = "FAILED", d = "FAILED", e = "PASSED", f = "PASSED"; michael@0: michael@0: function exceptArr() michael@0: { michael@0: return ["PASSED", {e: "PASSED", get f() { throw "PASSED"; }}, "FAILED"]; michael@0: } michael@0: michael@0: function partialEvalArr() michael@0: { michael@0: try michael@0: { michael@0: [c, {e: d, f: e}, f] = exceptArr(); michael@0: throw "FAILED"; michael@0: } michael@0: catch (ex) michael@0: { michael@0: if (ex !== "PASSED") michael@0: throw "bad exception thrown: " + ex; michael@0: } michael@0: } michael@0: michael@0: michael@0: var g = "FAILED", h = "FAILED", i = "FAILED", j = "FAILED", k = "FAILED"; michael@0: var _g = "PASSED", _h = "FAILED", _i = "FAILED", _j = "FAILED", _k = "FAILED"; michael@0: var order = []; michael@0: michael@0: function objWithGetters() michael@0: { michael@0: return { michael@0: get j() michael@0: { michael@0: var rv = _j; michael@0: _g = _h = _i = _j = "FAILED"; michael@0: _k = "PASSED"; michael@0: order.push("j"); michael@0: return rv; michael@0: }, michael@0: get g() michael@0: { michael@0: var rv = _g; michael@0: _g = _i = _j = _k = "FAILED"; michael@0: _h = "PASSED"; michael@0: order.push("g"); michael@0: return rv; michael@0: }, michael@0: get i() michael@0: { michael@0: var rv = _i; michael@0: _g = _h = _i = _k = "FAILED"; michael@0: _j = "PASSED"; michael@0: order.push("i"); michael@0: return rv; michael@0: }, michael@0: get k() michael@0: { michael@0: var rv = _k; michael@0: _g = _h = _i = _j = _k = "FAILED"; michael@0: order.push("k"); michael@0: return rv; michael@0: }, michael@0: get h() michael@0: { michael@0: var rv = _h; michael@0: _g = _h = _j = _k = "FAILED"; michael@0: _i = "PASSED"; michael@0: order.push("h"); michael@0: return rv; michael@0: } michael@0: }; michael@0: } michael@0: michael@0: function partialEvalObj2() michael@0: { michael@0: ({g: g, h: h, i: i, j: j, k: k}) = objWithGetters(); michael@0: } michael@0: michael@0: try michael@0: { michael@0: partialEvalObj(); michael@0: if (a !== "PASSED" || b !== "PASSED") michael@0: throw "FAILED: lhs not mutated correctly during destructuring!\n" + michael@0: "a == " + a + ", b == " + b; michael@0: michael@0: partialEvalObj2(); michael@0: if (g !== "PASSED" || michael@0: h !== "PASSED" || michael@0: i !== "PASSED" || michael@0: j !== "PASSED" || michael@0: k !== "PASSED") michael@0: throw "FAILED: order of property accesses wrong!\n" + michael@0: "order == " + order; michael@0: michael@0: partialEvalArr(); michael@0: if (c !== "PASSED" || d !== "PASSED" || e !== "PASSED") michael@0: throw "FAILED: lhs not mutated correctly during destructuring!\n" + michael@0: "c == " + c + michael@0: ", d == " + d + michael@0: ", e == " + e + michael@0: ", f == " + f ; michael@0: } michael@0: catch (ex) michael@0: { michael@0: failed = ex; michael@0: } michael@0: michael@0: expect = false; michael@0: actual = failed; michael@0: michael@0: reportCompare(expect, actual, summary);