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 33 function makeFuncAndCall(code) { 34 Function(code)(); 35 } 36 37 function makeFuncExpectError(code, ErrorType) { 38 try { 39 makeFuncAndCall(code); 40 } catch (e) { 41 if (! (e instanceof ErrorType)) { 42 fail(ErrorType.name + " expected, got " + e); 43 } 44 } 45 } 46 47 // makeFuncAndCall("switch(0) { default: {break;} return }"); 48 // makeFuncAndCall("L: { { break L; } return; }"); 49 makeFuncAndCall("L: { while(0) break L; return; }"); 50 makeFuncExpectError("L: {while(0) break L; return [](); }", TypeError); 51 // makeFuncAndCall("do with({}) break ; while(0);"); 52 makeFuncAndCall("while(0) with({}) continue ;"); 53 makeFuncAndCall("eval([]);"); 54 makeFuncAndCall("try{} finally{[]}"); 55 makeFuncAndCall("try { } catch(x if 1) { try { } catch(x2) { } }"); 56 makeFuncAndCall("try { } catch(x if 1) { try { return; } catch(x2) { { } } }"); 57 makeFuncAndCall("Error() * (false)[-0]--"); 58 makeFuncAndCall("try { var x = 1, x = null; } finally { }"); 59 makeFuncAndCall("try { var x = {}, x = []; } catch(x3) { }"); 60 makeFuncAndCall("[delete this]"); 61 // makeFuncAndCall("if(eval('', eval('', function() {}))) { }"); 62 // makeFuncAndCall("if(eval('', eval('', function() {}))) { }"); 63 // makeFuncAndCall("eval(\"[,,];\", [11,12,13,14].some)"); 64 // makeFuncAndCall("eval(\"1.2e3\", ({})[ /x/ ])"); 65 // makeFuncAndCall("eval(\"x4\", x3);"); 66 makeFuncAndCall("with({5.0000000000000000000000: String()}){(false); }"); 67 makeFuncAndCall("try { var x = undefined, x = 5.0000000000000000000000; } catch(x) { x = undefined; }"); 68 makeFuncAndCall("(function (x){ x %= this}(false))"); 69 // makeFuncAndCall("eval.apply.apply(function(){ eval('') })"); 70 makeFuncAndCall("(false % !this) && 0"); 71 makeFuncAndCall("with({8: 'fafafa'.replace()}){ }"); 72 makeFuncAndCall("(function (x) '' )(true)"); 73 makeFuncExpectError("new eval(function(){})", TypeError);