1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_8_5/regress/regress-609617.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* 1.6 + * Any copyright is dedicated to the Public Domain. 1.7 + * http://creativecommons.org/licenses/publicdomain/ 1.8 + */ 1.9 + 1.10 +var actual; 1.11 +var expect = "pass"; 1.12 + 1.13 +var x = "fail"; 1.14 +function f() { 1.15 + var x = "pass"; 1.16 + delete(eval("actual = x")); 1.17 +} 1.18 +f(); 1.19 +assertEq(actual, expect); 1.20 + 1.21 +function g() { return 1 } 1.22 +function h() { function g() { throw 2; } eval('g()')++; } 1.23 + 1.24 +try { 1.25 + h(); 1.26 + assertEq(0, -1); 1.27 +} catch (e) { 1.28 + assertEq(e, 2); 1.29 +} 1.30 + 1.31 +var lhs_prefix = ["", "++", "--", "", "", "[", "[y, " ]; 1.32 +var lhs_suffix = [" = 'no'", "", "", "++", "--", ", y] = [3, 4]", "] = [5, 6]"]; 1.33 + 1.34 +for (var i = 0; i < lhs_prefix.length; i++) { 1.35 + try { 1.36 + eval(lhs_prefix[i] + "eval('x')" + lhs_suffix[i]); 1.37 + assertEq(i, -2); 1.38 + } catch (e) { 1.39 + /* 1.40 + * NB: JSOP_SETCALL throws only JSMSG_BAD_LEFTSIDE_OF_ASS, it does not 1.41 + * specialize for ++ and -- as the compiler's error reporting does. See 1.42 + * the next section's forked assertEq code. 1.43 + */ 1.44 + assertEq(e.message, "invalid assignment left-hand side"); 1.45 + } 1.46 +} 1.47 + 1.48 +/* Destructuring desugars in the obvious way, so y must be 5 here. */ 1.49 +assertEq(y, 5); 1.50 + 1.51 +/* Now test for strict mode rejecting any SETCALL variant at compile time. */ 1.52 +for (var i = 0; i < lhs_prefix.length; i++) { 1.53 + try { 1.54 + eval("(function () { 'use strict'; " + lhs_prefix[i] + "foo('x')" + lhs_suffix[i] + "; })"); 1.55 + assertEq(i, -3); 1.56 + } catch (e) { 1.57 + if (/\+\+|\-\-/.test(lhs_prefix[i] || lhs_suffix[i])) 1.58 + assertEq(e.message, "invalid increment/decrement operand"); 1.59 + else 1.60 + assertEq(e.message, "invalid assignment left-hand side"); 1.61 + } 1.62 +} 1.63 + 1.64 +/* 1.65 + * The useless delete is optimized away, but the SETCALL must not be. It's not 1.66 + * an early error, though. 1.67 + */ 1.68 +var fooArg; 1.69 +function foo(arg) { fooArg = arg; } 1.70 +try { 1.71 + eval("delete (foo('x') = 42);"); 1.72 + assertEq(0, -4); 1.73 +} catch (e) { 1.74 + assertEq(e.message, "invalid assignment left-hand side"); 1.75 +} 1.76 +assertEq(fooArg, 'x'); 1.77 + 1.78 +/* Delete of a call expression is not an error at all, even in strict mode. */ 1.79 +function g() { 1.80 + "use strict"; 1.81 + assertEq(delete Object(), true); 1.82 +} 1.83 +g(); 1.84 + 1.85 +reportCompare(0, 0, "ok");