Debian Codegraph @

js/src/tests/non262/regress/regress-609617.js

raw
1 /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
2 /*
3 * Any copyright is dedicated to the Public Domain.
4 * http://creativecommons.org/licenses/publicdomain/
5 */
6
7 // SKIP test262 export
8 // https://github.com/tc39/ecma262/pull/2193
9
10 var actual;
11 var expect = "pass";
12
13 var x = "fail";
14 function f() {
15 var x = "pass";
16 delete(eval("actual = x"));
17 }
18 f();
19 assertEq(actual, expect);
20
21 function g() { return 1 }
22 function h() { function g() { throw 2; } eval('g()')++; }
23
24 assertThrowsValue(h, 2);
25
26 var lhs_prefix = ["", "++", "--", "", "", "[", "[y, " ];
27 var lhs_suffix = [" = 'no'", "", "", "++", "--", ", y] = [3, 4]", "] = [5, 6]"];
28
29 for (var i = 0; i < lhs_prefix.length; i++) {
30 var expected;
31 if (/\[/.test(lhs_prefix[i])) {
32 expected = "invalid destructuring target";
33 } else {
34 /*
35 * NB: JSOP_SETCALL throws only JSMSG_ASSIGN_TO_CALL, it does not
36 * specialize for ++ and -- as the compiler's error reporting does. See
37 * the next section's forked assertEq code.
38 */
39 expected = "cannot assign to function call";
40 }
41 assertThrownErrorContains(
42 () => eval(lhs_prefix[i] + "eval('x')" + lhs_suffix[i]),
43 expected);
44 }
45
46 /* Now test for strict mode rejecting any SETCALL variant at compile time. */
47 for (var i = 0; i < lhs_prefix.length; i++) {
48 var expected;
49 if (/\+\+|\-\-/.test(lhs_prefix[i] || lhs_suffix[i]))
50 expected = "invalid increment/decrement operand";
51 else if (/\[/.test(lhs_prefix[i]))
52 expected = "invalid destructuring target";
53 else
54 expected = "invalid assignment left-hand side";
55 assertThrownErrorContains(
56 () => eval("(function () { 'use strict'; " + lhs_prefix[i] + "foo('x')" + lhs_suffix[i] + "; })"),
57 expected);
58 }
59
60 /*
61 * The useless delete is optimized away, but the SETCALL must not be. It's not
62 * an early error, though.
63 */
64 var fooArg;
65 function foo(arg) { fooArg = arg; }
66 assertThrownErrorContains(
67 () => eval("delete (foo('x') = 42);"),
68 "cannot assign to function call");
69 assertEq(fooArg, 'x');
70
71 /* Delete of a call expression is not an error at all, even in strict mode. */
72 function g() {
73 "use strict";
74 assertEq(delete Object(), true);
75 }
76 g();
77
78 reportCompare(0, 0, "ok");