test/script/basic/NASHORN-19.js

Wed, 03 Jun 2015 18:08:57 +0200

author
hannesw
date
Wed, 03 Jun 2015 18:08:57 +0200
changeset 1396
d5a9705a27b1
parent 962
ac62e33a99b0
child 1205
4112748288bb
permissions
-rw-r--r--

8066237: Fuzzing bug: Parser error on optimistic recompilation
Reviewed-by: lagergren, attila

jlaskey@3 1 /*
jlaskey@7 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
jlaskey@3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
attila@962 4 *
jlaskey@3 5 * This code is free software; you can redistribute it and/or modify it
jlaskey@3 6 * under the terms of the GNU General Public License version 2 only, as
jlaskey@3 7 * published by the Free Software Foundation.
attila@962 8 *
jlaskey@3 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jlaskey@3 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jlaskey@3 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jlaskey@3 12 * version 2 for more details (a copy is included in the LICENSE file that
jlaskey@3 13 * accompanied this code).
attila@962 14 *
jlaskey@3 15 * You should have received a copy of the GNU General Public License version
jlaskey@3 16 * 2 along with this work; if not, write to the Free Software Foundation,
jlaskey@3 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
attila@962 18 *
jlaskey@3 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jlaskey@3 20 * or visit www.oracle.com if you need additional information or have any
jlaskey@3 21 * questions.
jlaskey@3 22 */
jlaskey@3 23
jlaskey@3 24 /**
jlaskey@3 25 * NASHORN-19: with blocks in various scopes and breaking from them if they are inloops
jlaskey@3 26 * (also continues)
jlaskey@3 27 *
jlaskey@3 28 * @test
jlaskey@3 29 * @run
jlaskey@3 30 */
jlaskey@3 31
jlaskey@3 32
jlaskey@3 33 var myvalue = "hello";
jlaskey@3 34
jlaskey@3 35 var myscope = {
jlaskey@3 36 myvalue: 11
jlaskey@3 37 };
jlaskey@3 38
jlaskey@3 39 do {
jlaskey@3 40 with(myscope) {
attila@962 41 myvalue = 12;
attila@962 42 break;
jlaskey@3 43 }
jlaskey@3 44 } while (false);
jlaskey@3 45
jlaskey@3 46 if (myvalue != 'hello') {
jlaskey@3 47 throw "expecting to be hello";
jlaskey@3 48 } else {
jlaskey@3 49 print("value is 'hello' as expected");
jlaskey@3 50 }
jlaskey@3 51
jlaskey@3 52 print("\n");
jlaskey@3 53
jlaskey@3 54 function ten() {
jlaskey@3 55 return 0xa;
jlaskey@3 56 }
jlaskey@3 57
jlaskey@3 58 //make sure the scope works outside functions too
jlaskey@3 59 print("starting 0");
jlaskey@3 60 var value = "hello";
jlaskey@3 61 var scope = {value:10};
jlaskey@3 62 var scope2 = {value:20};
jlaskey@3 63 while (true) {
jlaskey@3 64 with (scope) {
attila@962 65 print(value);
attila@962 66 value = 11;
attila@962 67 print(value);
attila@962 68 with (scope2) {
attila@962 69 print(value);
attila@962 70 value = 21;
attila@962 71 print(value);
attila@962 72 break;
attila@962 73 }
jlaskey@3 74 }
jlaskey@3 75 }
jlaskey@3 76
jlaskey@3 77 print(value);
jlaskey@3 78 print("\n");
jlaskey@3 79
jlaskey@3 80 //two level scope
jlaskey@3 81 function test1() {
jlaskey@3 82 var value = "hello";
jlaskey@3 83 var scope = {value:10};
jlaskey@3 84 var scope2 = {value:20};
jlaskey@3 85 while (true) {
attila@962 86 with (scope) {
attila@962 87 print(value);
attila@962 88 value = 11;
attila@962 89 print(value);
attila@962 90 with (scope2) {
attila@962 91 print(value);
attila@962 92 value = 21;
attila@962 93 print(value);
attila@962 94 break;
attila@962 95 }
jlaskey@3 96 }
attila@962 97 }
attila@962 98
jlaskey@3 99 print(value);
jlaskey@3 100 }
jlaskey@3 101
jlaskey@3 102 //one level scope
jlaskey@3 103 function test2() {
jlaskey@3 104 var value = "hello";
jlaskey@3 105 var scope = {value:10};
jlaskey@3 106 while (true) {
attila@962 107 with (scope) {
attila@962 108 print(value);
attila@962 109 value = 11;
attila@962 110 print(value);
attila@962 111 if (value > ten()) {
attila@962 112 break;
attila@962 113 }
attila@962 114 }
jlaskey@3 115 }
jlaskey@3 116 print(value);
jlaskey@3 117 }
jlaskey@3 118
jlaskey@3 119 //continue two levels
jlaskey@3 120 function test3() {
jlaskey@3 121 var value = "hello";
jlaskey@3 122 var scope = {value:10};
jlaskey@3 123 var scope2 = {value:20};
jlaskey@3 124 var outer = 0;
jlaskey@3 125 while (outer < 5) {
attila@962 126 var i=0;
attila@962 127 while (i < 10) {
attila@962 128 with(scope) {
attila@962 129 print("loop header "+i);
attila@962 130 with (scope2) {
attila@962 131 value = 11;
attila@962 132 i++;
attila@962 133 if ((i & 1) != 0) {
attila@962 134 print("continue");
attila@962 135 continue;
attila@962 136 }
attila@962 137 }
attila@962 138 }
attila@962 139 print(value);
jlaskey@3 140 }
attila@962 141 outer++;
attila@962 142 }
attila@962 143 }
jlaskey@3 144
jlaskey@3 145 //continue one level
jlaskey@3 146 function test4() {
jlaskey@3 147 var value = "hello";
jlaskey@3 148 var scope = {value:10};
jlaskey@3 149 var i=0;
jlaskey@3 150 while (i < 10) {
attila@962 151 print("loop header "+i);
attila@962 152 with (scope) {
attila@962 153 value = 11;
attila@962 154 i++;
attila@962 155 if ((i & 1) != 0) {
attila@962 156 print("continue");
attila@962 157 continue;
attila@962 158 }
attila@962 159 }
jlaskey@3 160 }
jlaskey@3 161 print(value);
jlaskey@3 162 }
jlaskey@3 163
jlaskey@3 164
jlaskey@3 165 //labelled continue;
jlaskey@3 166 function test5() {
jlaskey@3 167 var value = "hello";
jlaskey@3 168 var scope = {value:10};
jlaskey@3 169 var scope2 = {value:20};
jlaskey@3 170 var outer = 0;
jlaskey@3 171 outer_label:
jlaskey@3 172 while (outer < 5) {
attila@962 173 var i=0;
attila@962 174 while (i < 10) {
attila@962 175 with(scope) {
attila@962 176 print("loop header "+i);
attila@962 177 with (scope2) {
attila@962 178 value = 11;
attila@962 179 i++;
attila@962 180 if ((i & 1) != 0) {
attila@962 181 print("continue");
attila@962 182 outer++;
attila@962 183 continue outer_label;
attila@962 184 }
attila@962 185 }
attila@962 186 }
attila@962 187 print(value);
jlaskey@3 188 }
attila@962 189 }
attila@962 190 }
jlaskey@3 191
jlaskey@3 192 //labelled break
jlaskey@3 193 function test6() {
jlaskey@3 194 var value = "hello";
jlaskey@3 195 var scope = {value:10};
jlaskey@3 196 var scope2 = {value:20};
jlaskey@3 197 outer:
jlaskey@3 198 {
attila@962 199 var i=0;
attila@962 200 while (i < 10) {
attila@962 201 with(scope) {
attila@962 202 print("loop header "+i);
attila@962 203 with (scope2) {
attila@962 204 value = 11;
attila@962 205 i++;
attila@962 206 if ((i & 1) != 0) {
attila@962 207 print("break");
attila@962 208 break outer;
attila@962 209 }
attila@962 210 }
attila@962 211 }
attila@962 212 print(value);
attila@962 213 }
jlaskey@3 214 }
jlaskey@3 215 }
jlaskey@3 216
jlaskey@3 217 //exceptions in one scope and then the other
jlaskey@3 218 function test7() {
jlaskey@3 219 var value = "hello";
jlaskey@3 220 var scope = {value:10};
attila@962 221 var scope2 = {value:20};
jlaskey@3 222 var global = false;
jlaskey@3 223 try {
attila@962 224 with(scope) {
attila@962 225 try {
attila@962 226 print(value);
attila@962 227 value = 4711;
attila@962 228 print(value);
attila@962 229 with(scope2) {
attila@962 230 print(value);
attila@962 231 value = 17;
attila@962 232 print(value);
attila@962 233 global = true;
attila@962 234 throw "inner";
attila@962 235 }
attila@962 236 } catch (ei) {
attila@962 237 print(ei);
attila@962 238 print(value);
attila@962 239 if (global) {
attila@962 240 throw "outer";
attila@962 241 }
attila@962 242 }
attila@962 243 }
jlaskey@3 244 } catch (eo) {
attila@962 245 print(eo);
attila@962 246 print(value);
jlaskey@3 247 }
jlaskey@3 248 print(value);
jlaskey@3 249 }
jlaskey@3 250
jlaskey@3 251
jlaskey@3 252 print("starting 1");
jlaskey@3 253 test1();
jlaskey@3 254 print("\n");
jlaskey@3 255
jlaskey@3 256 print("starting 2");
jlaskey@3 257 test2();
jlaskey@3 258 print("\n");
jlaskey@3 259
jlaskey@3 260 print("starting 3");
jlaskey@3 261 test3();
jlaskey@3 262 print("\n");
jlaskey@3 263
jlaskey@3 264 print("starting 4");
jlaskey@3 265 test4();
jlaskey@3 266 print("\n");
jlaskey@3 267
jlaskey@3 268 print("starting 5");
jlaskey@3 269 test5();
jlaskey@3 270 print("\n");
jlaskey@3 271
jlaskey@3 272 print("starting 6");
jlaskey@3 273 test6();
jlaskey@3 274 print("\n");
jlaskey@3 275
jlaskey@3 276 print("starting 7");
jlaskey@3 277 test7();
jlaskey@3 278 print("\n");
jlaskey@3 279

mercurial