michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: var actual; michael@0: var expect = "pass"; michael@0: michael@0: var x = "fail"; michael@0: function f() { michael@0: var x = "pass"; michael@0: delete(eval("actual = x")); michael@0: } michael@0: f(); michael@0: assertEq(actual, expect); michael@0: michael@0: function g() { return 1 } michael@0: function h() { function g() { throw 2; } eval('g()')++; } michael@0: michael@0: try { michael@0: h(); michael@0: assertEq(0, -1); michael@0: } catch (e) { michael@0: assertEq(e, 2); michael@0: } michael@0: michael@0: var lhs_prefix = ["", "++", "--", "", "", "[", "[y, " ]; michael@0: var lhs_suffix = [" = 'no'", "", "", "++", "--", ", y] = [3, 4]", "] = [5, 6]"]; michael@0: michael@0: for (var i = 0; i < lhs_prefix.length; i++) { michael@0: try { michael@0: eval(lhs_prefix[i] + "eval('x')" + lhs_suffix[i]); michael@0: assertEq(i, -2); michael@0: } catch (e) { michael@0: /* michael@0: * NB: JSOP_SETCALL throws only JSMSG_BAD_LEFTSIDE_OF_ASS, it does not michael@0: * specialize for ++ and -- as the compiler's error reporting does. See michael@0: * the next section's forked assertEq code. michael@0: */ michael@0: assertEq(e.message, "invalid assignment left-hand side"); michael@0: } michael@0: } michael@0: michael@0: /* Destructuring desugars in the obvious way, so y must be 5 here. */ michael@0: assertEq(y, 5); michael@0: michael@0: /* Now test for strict mode rejecting any SETCALL variant at compile time. */ michael@0: for (var i = 0; i < lhs_prefix.length; i++) { michael@0: try { michael@0: eval("(function () { 'use strict'; " + lhs_prefix[i] + "foo('x')" + lhs_suffix[i] + "; })"); michael@0: assertEq(i, -3); michael@0: } catch (e) { michael@0: if (/\+\+|\-\-/.test(lhs_prefix[i] || lhs_suffix[i])) michael@0: assertEq(e.message, "invalid increment/decrement operand"); michael@0: else michael@0: assertEq(e.message, "invalid assignment left-hand side"); michael@0: } michael@0: } michael@0: michael@0: /* michael@0: * The useless delete is optimized away, but the SETCALL must not be. It's not michael@0: * an early error, though. michael@0: */ michael@0: var fooArg; michael@0: function foo(arg) { fooArg = arg; } michael@0: try { michael@0: eval("delete (foo('x') = 42);"); michael@0: assertEq(0, -4); michael@0: } catch (e) { michael@0: assertEq(e.message, "invalid assignment left-hand side"); michael@0: } michael@0: assertEq(fooArg, 'x'); michael@0: michael@0: /* Delete of a call expression is not an error at all, even in strict mode. */ michael@0: function g() { michael@0: "use strict"; michael@0: assertEq(delete Object(), true); michael@0: } michael@0: g(); michael@0: michael@0: reportCompare(0, 0, "ok");