Wed, 05 Sep 2018 01:21:35 -0700
Added tag jdk8u192-b09 for changeset 456c0d45c43b
attila@963 | 1 | /* |
attila@963 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
attila@963 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
attila@963 | 4 | * |
attila@963 | 5 | * This code is free software; you can redistribute it and/or modify it |
attila@963 | 6 | * under the terms of the GNU General Public License version 2 only, as |
attila@963 | 7 | * published by the Free Software Foundation. |
attila@963 | 8 | * |
attila@963 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
attila@963 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
attila@963 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
attila@963 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
attila@963 | 13 | * accompanied this code). |
attila@963 | 14 | * |
attila@963 | 15 | * You should have received a copy of the GNU General Public License version |
attila@963 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
attila@963 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
attila@963 | 18 | * |
attila@963 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
attila@963 | 20 | * or visit www.oracle.com if you need additional information or have any |
attila@963 | 21 | * questions. |
attila@963 | 22 | */ |
attila@963 | 23 | |
attila@963 | 24 | /** |
attila@963 | 25 | * JDK-8047369: Add regression tests for passing test cases of JDK-8024971 |
attila@963 | 26 | * |
attila@963 | 27 | * @test |
attila@963 | 28 | * @run |
attila@963 | 29 | * @option -scripting |
attila@963 | 30 | */ |
attila@963 | 31 | |
attila@963 | 32 | function makeFuncAndCall(code) { |
attila@963 | 33 | Function(code)(); |
attila@963 | 34 | } |
attila@963 | 35 | |
attila@963 | 36 | function makeFuncExpectError(code, ErrorType) { |
attila@963 | 37 | try { |
attila@963 | 38 | makeFuncAndCall(code); |
attila@963 | 39 | } catch (e) { |
attila@963 | 40 | if (! (e instanceof ErrorType)) { |
attila@963 | 41 | fail(ErrorType.name + " expected, got " + e); |
attila@963 | 42 | } |
attila@963 | 43 | } |
attila@963 | 44 | } |
attila@963 | 45 | |
attila@963 | 46 | function evalExpectError(code, ErrorType) { |
attila@963 | 47 | try { |
attila@963 | 48 | eval(code)(); |
attila@963 | 49 | } catch (e) { |
attila@963 | 50 | if (! (e instanceof ErrorType)) { |
attila@963 | 51 | fail(ErrorType.name + " expected, got " + e); |
attila@963 | 52 | } |
attila@963 | 53 | } |
attila@963 | 54 | } |
attila@963 | 55 | |
attila@963 | 56 | function evalExpectValue(code, value) { |
attila@963 | 57 | if (eval(code) != value) { |
attila@963 | 58 | fail("Expected " + value + " with eval of " + code); |
attila@963 | 59 | } |
attila@963 | 60 | } |
attila@963 | 61 | |
attila@963 | 62 | makeFuncAndCall("for(x.x in 0) {}"); |
attila@963 | 63 | // bug JDK-8047357 |
attila@963 | 64 | // makeFuncAndCall("switch((null >> x3)) { default: {var x; break ; }\nthrow x; }"); |
attila@963 | 65 | makeFuncExpectError("switch(x) { case 8: break; case false: }", ReferenceError); |
attila@963 | 66 | makeFuncAndCall("try { return true; } finally { return false; } "); |
attila@963 | 67 | makeFuncAndCall("({ get 1e81(){} })"); |
attila@963 | 68 | makeFuncAndCall("{var x, x3;try { return 0; } finally { return 3/0; } }"); |
attila@963 | 69 | makeFuncExpectError("with(x ? 1e81 : (x2.constructor = 0.1)) {}", ReferenceError); |
attila@963 | 70 | makeFuncAndCall("while(x-=1) {var x=0; }"); |
attila@963 | 71 | makeFuncAndCall("while((x-=false) && 0) { var x = this; }"); |
attila@963 | 72 | makeFuncAndCall("/*infloop*/while(x4-=x) var x, x4 = x1;"); |
attila@963 | 73 | makeFuncAndCall("/*infloop*/L:while(x+=null) { this;var x = /x/g ; }"); |
attila@963 | 74 | makeFuncAndCall("while((x1|=0.1) && 0) { var x1 = -0, functional; }"); |
attila@963 | 75 | makeFuncAndCall("with({}) return (eval(\"arguments\"));"); |
attila@963 | 76 | |
attila@963 | 77 | evalExpectValue(<<CODE |
attila@963 | 78 | var s = "(function() { return y })()"; |
attila@963 | 79 | (function() { |
attila@963 | 80 | with({ y:1 }) |
attila@963 | 81 | eval(s) |
attila@963 | 82 | })(); |
attila@963 | 83 | (function() { |
attila@963 | 84 | with({ |
attila@963 | 85 | get y() { return "get"; } |
attila@963 | 86 | }) |
attila@963 | 87 | return eval(s) |
attila@963 | 88 | })(); |
attila@963 | 89 | CODE, "get"); |
attila@963 | 90 | |
attila@963 | 91 | // bug JDK-8047359 |
attila@963 | 92 | // evalExpectValue("s = ' '; for (var i=0;i<31;++i) s+=s; s.length", RangeError); |
attila@963 | 93 | |
attila@963 | 94 | evalExpectValue(<<CODE |
attila@963 | 95 | function f(o) { |
attila@963 | 96 | var eval=0; |
attila@963 | 97 | with({ |
attila@963 | 98 | get eval() { return o.eval } |
attila@963 | 99 | }) |
attila@963 | 100 | return eval("1+2"); |
attila@963 | 101 | } |
attila@963 | 102 | f(this); |
attila@963 | 103 | CODE, 3) |
attila@963 | 104 | |
attila@963 | 105 | evalExpectValue(<<CODE |
attila@963 | 106 | function f() { |
attila@963 | 107 | var a=1,e=2; |
attila@963 | 108 | try { |
attila@963 | 109 | throw 3 |
attila@963 | 110 | } catch(e) { |
attila@963 | 111 | return + function g(){return eval('a+e')}() |
attila@963 | 112 | } |
attila@963 | 113 | } |
attila@963 | 114 | f(); |
attila@963 | 115 | CODE, 4); |
attila@963 | 116 | |
attila@963 | 117 | //evalExpectValue( |
attila@963 | 118 | // "function f(){var a=1; with({get a(){return false}}) return a}; f()", false); |
attila@963 | 119 | |
attila@963 | 120 | evalExpectError("function public() {\"use strict\"}", SyntaxError); |
attila@963 | 121 | evalExpectError("function f(public) {\"use strict\"}", SyntaxError); |
attila@963 | 122 | evalExpectError("function f() { switch(x) {} } f()", ReferenceError); |
attila@963 | 123 | |
attila@963 | 124 | // bug JDK-8047364 |
attila@963 | 125 | // makeFuncAndCall("L1:try { return } finally { break L1 }"); |
attila@963 | 126 | |
attila@963 | 127 | evalExpectValue(<<CODE |
attila@963 | 128 | function f() { |
attila@963 | 129 | function g() { return 0 } |
attila@963 | 130 | function g() { return 1 } |
attila@963 | 131 | function g$1() { return 2 } |
attila@963 | 132 | return g$1() |
attila@963 | 133 | } |
attila@963 | 134 | |
attila@963 | 135 | f(); |
attila@963 | 136 | CODE, 2); |
attila@963 | 137 | |
attila@963 | 138 | evalExpectValue(<<CODE |
attila@963 | 139 | function f() { |
attila@963 | 140 | function g() {return 0 } |
attila@963 | 141 | var h = function g() { return 1 }; |
attila@963 | 142 | function g$1() { return 2 }; |
attila@963 | 143 | return h() |
attila@963 | 144 | } |
attila@963 | 145 | |
attila@963 | 146 | f() |
attila@963 | 147 | CODE, 1); |
attila@963 | 148 | |
attila@963 | 149 | evalExpectValue(<<CODE |
attila@963 | 150 | function f() { |
attila@963 | 151 | var obj = { get ":"() {} } |
attila@963 | 152 | var desc = Object.getOwnPropertyDescriptor(obj, ":") |
attila@963 | 153 | return desc.get.name |
attila@963 | 154 | } |
attila@963 | 155 | |
attila@963 | 156 | f() |
attila@963 | 157 | CODE, ":"); |
attila@963 | 158 | |
attila@963 | 159 | evalExpectValue(<<CODE |
attila@963 | 160 | function f() { |
attila@963 | 161 | var obj = { set ":"(a) {} }; |
attila@963 | 162 | var desc = Object.getOwnPropertyDescriptor(obj, ":"); |
attila@963 | 163 | return desc.set; |
attila@963 | 164 | } |
attila@963 | 165 | |
attila@963 | 166 | f() |
attila@963 | 167 | CODE, "set \":\"(a) {}"); |
attila@963 | 168 | |
attila@963 | 169 | // bug JDK-8047366 |
attila@963 | 170 | // evalExpectValue("(1000000000000000128).toString()", "1000000000000000100"); |
attila@963 | 171 | // evalExpectValue("(1000000000000000128).toFixed().toString()", "1000000000000000128"); |
attila@963 | 172 | |
attila@963 | 173 | try { |
attila@963 | 174 | Function("-", { |
attila@963 | 175 | toString: function() { |
attila@963 | 176 | throw "err" |
attila@963 | 177 | } |
attila@963 | 178 | })(); |
attila@963 | 179 | } catch (e) { |
attila@963 | 180 | if (e != "err") { |
attila@963 | 181 | fail("Expected 'err' here, got " + e); |
attila@963 | 182 | } |
attila@963 | 183 | } |
attila@963 | 184 | evalExpectError("function f() { switch(x) {} } f()", ReferenceError); |
attila@963 | 185 | Array.prototype.splice.call(Java.type("java.util.HashMap")) |
attila@963 | 186 | Array.prototype.slice.call(Java.type("java.util.HashMap")) |