JDK-8047057.js revision 904:6afee63aa1cc
1/*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/**
25 * JDK-8047057: Add a regression test for the passing test cases from JDK-8042304
26 *
27 * @test
28 * @run
29 */
30
31// commented out makeFuncAndCall calls are still result in crash
32// Tests commented with //** fail only when assertions are turned on
33
34function makeFuncAndCall(code) {
35    Function(code)();
36}
37
38function makeFuncExpectError(code, ErrorType) {
39    try {
40        makeFuncAndCall(code);
41    } catch (e) {
42        if (! (e instanceof ErrorType)) {
43            fail(ErrorType.name + " expected, got " + e);
44        }
45    }
46}
47
48// makeFuncAndCall("switch(0) { default: {break;} return }");
49// makeFuncAndCall("L: { { break L; } return; }");
50makeFuncAndCall("L: { while(0) break L; return; }");
51makeFuncExpectError("L: {while(0) break L; return [](); }", TypeError);
52// makeFuncAndCall("do with({}) break ; while(0);");
53makeFuncAndCall("while(0) with({}) continue ;");
54makeFuncAndCall("eval([]);");
55makeFuncAndCall("try{} finally{[]}");
56makeFuncAndCall("try { } catch(x if 1) { try { } catch(x2) { } }");
57makeFuncAndCall("try { } catch(x if 1) { try { return; } catch(x2) { { } } }");
58makeFuncAndCall("Error() * (false)[-0]--");
59makeFuncAndCall("try { var x = 1, x = null; } finally { }");
60makeFuncAndCall("try { var x = {}, x = []; } catch(x3) { }");
61makeFuncAndCall("[delete this]");
62// makeFuncAndCall("if(eval('', eval('', function() {}))) { }");
63// makeFuncAndCall("if(eval('', eval('', function() {}))) { }");
64// makeFuncAndCall("eval(\"[,,];\", [11,12,13,14].some)");
65// makeFuncAndCall("eval(\"1.2e3\", ({})[ /x/ ])");
66makeFuncExpectError("eval(\"x4\", x3);", ReferenceError);
67makeFuncAndCall("with({5.0000000000000000000000: String()}){(false); }");
68makeFuncAndCall("try { var x = undefined, x = 5.0000000000000000000000; } catch(x) { x = undefined; }");
69makeFuncAndCall("(function (x){ x %= this}(false))");
70makeFuncAndCall("eval.apply.apply(function(){ eval('') })");
71makeFuncAndCall("(false % !this) && 0");
72makeFuncAndCall("with({8: 'fafafa'.replace()}){ }");
73makeFuncAndCall("(function (x) '' )(true)");
74makeFuncExpectError("new eval(function(){})", TypeError);
75//** makeFuncAndCall('eval("23", ({})[/x/])');
76