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