1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/script/basic/JDK-8047369.js Wed Aug 20 10:26:01 2014 +0200 1.3 @@ -0,0 +1,186 @@ 1.4 +/* 1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/** 1.28 + * JDK-8047369: Add regression tests for passing test cases of JDK-8024971 1.29 + * 1.30 + * @test 1.31 + * @run 1.32 + * @option -scripting 1.33 + */ 1.34 + 1.35 +function makeFuncAndCall(code) { 1.36 + Function(code)(); 1.37 +} 1.38 + 1.39 +function makeFuncExpectError(code, ErrorType) { 1.40 + try { 1.41 + makeFuncAndCall(code); 1.42 + } catch (e) { 1.43 + if (! (e instanceof ErrorType)) { 1.44 + fail(ErrorType.name + " expected, got " + e); 1.45 + } 1.46 + } 1.47 +} 1.48 + 1.49 +function evalExpectError(code, ErrorType) { 1.50 + try { 1.51 + eval(code)(); 1.52 + } catch (e) { 1.53 + if (! (e instanceof ErrorType)) { 1.54 + fail(ErrorType.name + " expected, got " + e); 1.55 + } 1.56 + } 1.57 +} 1.58 + 1.59 +function evalExpectValue(code, value) { 1.60 + if (eval(code) != value) { 1.61 + fail("Expected " + value + " with eval of " + code); 1.62 + } 1.63 +} 1.64 + 1.65 +makeFuncAndCall("for(x.x in 0) {}"); 1.66 +// bug JDK-8047357 1.67 +// makeFuncAndCall("switch((null >> x3)) { default: {var x; break ; }\nthrow x; }"); 1.68 +makeFuncExpectError("switch(x) { case 8: break; case false: }", ReferenceError); 1.69 +makeFuncAndCall("try { return true; } finally { return false; } "); 1.70 +makeFuncAndCall("({ get 1e81(){} })"); 1.71 +makeFuncAndCall("{var x, x3;try { return 0; } finally { return 3/0; } }"); 1.72 +makeFuncExpectError("with(x ? 1e81 : (x2.constructor = 0.1)) {}", ReferenceError); 1.73 +makeFuncAndCall("while(x-=1) {var x=0; }"); 1.74 +makeFuncAndCall("while((x-=false) && 0) { var x = this; }"); 1.75 +makeFuncAndCall("/*infloop*/while(x4-=x) var x, x4 = x1;"); 1.76 +makeFuncAndCall("/*infloop*/L:while(x+=null) { this;var x = /x/g ; }"); 1.77 +makeFuncAndCall("while((x1|=0.1) && 0) { var x1 = -0, functional; }"); 1.78 +makeFuncAndCall("with({}) return (eval(\"arguments\"));"); 1.79 + 1.80 +evalExpectValue(<<CODE 1.81 + var s = "(function() { return y })()"; 1.82 + (function() { 1.83 + with({ y:1 }) 1.84 + eval(s) 1.85 + })(); 1.86 + (function() { 1.87 + with({ 1.88 + get y() { return "get"; } 1.89 + }) 1.90 + return eval(s) 1.91 + })(); 1.92 +CODE, "get"); 1.93 + 1.94 +// bug JDK-8047359 1.95 +// evalExpectValue("s = ' '; for (var i=0;i<31;++i) s+=s; s.length", RangeError); 1.96 + 1.97 +evalExpectValue(<<CODE 1.98 + function f(o) { 1.99 + var eval=0; 1.100 + with({ 1.101 + get eval() { return o.eval } 1.102 + }) 1.103 + return eval("1+2"); 1.104 + } 1.105 + f(this); 1.106 +CODE, 3) 1.107 + 1.108 +evalExpectValue(<<CODE 1.109 + function f() { 1.110 + var a=1,e=2; 1.111 + try { 1.112 + throw 3 1.113 + } catch(e) { 1.114 + return + function g(){return eval('a+e')}() 1.115 + } 1.116 + } 1.117 + f(); 1.118 +CODE, 4); 1.119 + 1.120 +//evalExpectValue( 1.121 +// "function f(){var a=1; with({get a(){return false}}) return a}; f()", false); 1.122 + 1.123 +evalExpectError("function public() {\"use strict\"}", SyntaxError); 1.124 +evalExpectError("function f(public) {\"use strict\"}", SyntaxError); 1.125 +evalExpectError("function f() { switch(x) {} } f()", ReferenceError); 1.126 + 1.127 +// bug JDK-8047364 1.128 +// makeFuncAndCall("L1:try { return } finally { break L1 }"); 1.129 + 1.130 +evalExpectValue(<<CODE 1.131 + function f() { 1.132 + function g() { return 0 } 1.133 + function g() { return 1 } 1.134 + function g$1() { return 2 } 1.135 + return g$1() 1.136 + } 1.137 + 1.138 + f(); 1.139 +CODE, 2); 1.140 + 1.141 +evalExpectValue(<<CODE 1.142 + function f() { 1.143 + function g() {return 0 } 1.144 + var h = function g() { return 1 }; 1.145 + function g$1() { return 2 }; 1.146 + return h() 1.147 + } 1.148 + 1.149 + f() 1.150 +CODE, 1); 1.151 + 1.152 +evalExpectValue(<<CODE 1.153 + function f() { 1.154 + var obj = { get ":"() {} } 1.155 + var desc = Object.getOwnPropertyDescriptor(obj, ":") 1.156 + return desc.get.name 1.157 + } 1.158 + 1.159 + f() 1.160 +CODE, ":"); 1.161 + 1.162 +evalExpectValue(<<CODE 1.163 + function f() { 1.164 + var obj = { set ":"(a) {} }; 1.165 + var desc = Object.getOwnPropertyDescriptor(obj, ":"); 1.166 + return desc.set; 1.167 + } 1.168 + 1.169 + f() 1.170 +CODE, "set \":\"(a) {}"); 1.171 + 1.172 +// bug JDK-8047366 1.173 +// evalExpectValue("(1000000000000000128).toString()", "1000000000000000100"); 1.174 +// evalExpectValue("(1000000000000000128).toFixed().toString()", "1000000000000000128"); 1.175 + 1.176 +try { 1.177 + Function("-", { 1.178 + toString: function() { 1.179 + throw "err" 1.180 + } 1.181 + })(); 1.182 +} catch (e) { 1.183 + if (e != "err") { 1.184 + fail("Expected 'err' here, got " + e); 1.185 + } 1.186 +} 1.187 +evalExpectError("function f() { switch(x) {} } f()", ReferenceError); 1.188 +Array.prototype.splice.call(Java.type("java.util.HashMap")) 1.189 +Array.prototype.slice.call(Java.type("java.util.HashMap"))