OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 3 // |
| 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions |
| 6 // are met: |
| 7 // 1. Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. |
| 9 // 2. Redistributions in binary form must reproduce the above copyright |
| 10 // notice, this list of conditions and the following disclaimer in the |
| 11 // documentation and/or other materials provided with the distribution. |
| 12 // |
| 13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 |
| 24 description("KDE JS Test"); |
| 25 var global = this; |
| 26 function myfunc() { |
| 27 } |
| 28 function throwex() { |
| 29 throw new Error("test exception"); |
| 30 } |
| 31 |
| 32 //--------------------------- |
| 33 var func_ret_with_ex_func = 4; |
| 34 try { |
| 35 func_ret_with_ex_func = throwex()(); |
| 36 } |
| 37 catch (e) { |
| 38 } |
| 39 shouldBe("func_ret_with_ex_func", "4"); |
| 40 |
| 41 // --------------------------------- |
| 42 |
| 43 var func_ret_from_ex_throw_args = 4; |
| 44 try { |
| 45 func_ret_from_ex_throw_args = Math.abs(throwex()); |
| 46 } |
| 47 catch (e) { |
| 48 } |
| 49 shouldBe("func_ret_from_ex_throw_args", "4"); |
| 50 |
| 51 // --------------------------------- |
| 52 |
| 53 var set_from_throw_func_args = 4; |
| 54 try { |
| 55 throwex()(set_from_throw_func_args = 1); |
| 56 } |
| 57 catch (e) { |
| 58 } |
| 59 shouldBe("set_from_throw_func_args","4"); |
| 60 |
| 61 // --------------------------------- |
| 62 |
| 63 var set_from_func_throw_args = 4; |
| 64 try { |
| 65 myfunc(throwex(), set_from_func_throw_args = 1); |
| 66 } |
| 67 catch (e) { |
| 68 } |
| 69 shouldBe("set_from_func_throw_args","4"); |
| 70 |
| 71 // --------------------------------- |
| 72 |
| 73 var set_from_before_func_throw_args = 4; |
| 74 try { |
| 75 myfunc(set_from_before_func_throw_args = 1, throwex()); |
| 76 } |
| 77 catch (e) { |
| 78 } |
| 79 shouldBe("set_from_before_func_throw_args","1"); |
| 80 |
| 81 // --------------------------------- |
| 82 |
| 83 // ### move to function.js |
| 84 var function_param_order = ""; |
| 85 function aparam() { |
| 86 function_param_order += "a"; |
| 87 } |
| 88 function bparam() { |
| 89 function_param_order += "b"; |
| 90 } |
| 91 function cparam() { |
| 92 function_param_order += "c"; |
| 93 } |
| 94 myfunc(aparam(),bparam(),cparam()); |
| 95 shouldBe("function_param_order","'abc'"); |
| 96 |
| 97 // --------------------------------- |
| 98 // ### move to function.js |
| 99 var new_param_order = ""; |
| 100 function anewparam() { |
| 101 new_param_order += "a"; |
| 102 } |
| 103 function bnewparam() { |
| 104 new_param_order += "b"; |
| 105 } |
| 106 function cnewparam() { |
| 107 new_param_order += "c"; |
| 108 } |
| 109 new myfunc(anewparam(),bnewparam(),cnewparam()); |
| 110 shouldBe("new_param_order","'abc'"); |
| 111 |
| 112 // --------------------------------- |
| 113 // ### move to function.js |
| 114 var elision_param_order = ""; |
| 115 function aelision() { |
| 116 elision_param_order += "a"; |
| 117 } |
| 118 function belision() { |
| 119 elision_param_order += "b"; |
| 120 } |
| 121 function celision() { |
| 122 elision_param_order += "c"; |
| 123 } |
| 124 [aelision(),belision(),celision()]; |
| 125 shouldBe("elision_param_order","'abc'"); |
| 126 |
| 127 // --------------------------------- |
| 128 // ### move to function.js |
| 129 var comma_order = ""; |
| 130 function acomma() { |
| 131 comma_order += "a"; |
| 132 } |
| 133 function bcomma() { |
| 134 comma_order += "b"; |
| 135 } |
| 136 function ccomma() { |
| 137 comma_order += "c"; |
| 138 } |
| 139 acomma(),bcomma(),ccomma(); |
| 140 shouldBe("comma_order","'abc'"); |
| 141 |
| 142 // --------------------------------- |
| 143 |
| 144 function checkOperator(op,name) { |
| 145 var code =( |
| 146 "global."+name+"_part1 = 4;\n"+ |
| 147 "try {\n"+ |
| 148 " ("+name+"_part1 = 1) "+op+" throwex();\n"+ |
| 149 "}\n"+ |
| 150 "catch (e) {\n"+ |
| 151 "}\n"+ |
| 152 "shouldBe('"+name+"_part1', '1');\n"+ |
| 153 "global."+name+"_part2 = 4;\n"+ |
| 154 "try {\n"+ |
| 155 " throwex() "+op+" ("+name+"_part2 = 1);\n"+ |
| 156 "}\n"+ |
| 157 "catch (e) {\n"+ |
| 158 "}\n"+ |
| 159 "shouldBe('"+name+"_part2', '4');\n"); |
| 160 // print("\n\n\n"); |
| 161 // print(code); |
| 162 eval(code); |
| 163 } |
| 164 |
| 165 checkOperator("==","OpEqEq"); |
| 166 checkOperator("!=","OpNotEq"); |
| 167 checkOperator("===","OpStrEq"); |
| 168 checkOperator("!==","OpStrNEq"); |
| 169 // ### these generate a syntax error in mozilla - kjs should do the same (?) |
| 170 //checkOperator("+=","OpPlusEq"); |
| 171 //checkOperator("-=","OpMinusEq"); |
| 172 //checkOperator("*=","OpMultEq"); |
| 173 //checkOperator("/=","OpDivEq"); |
| 174 // OpPlusPlus, |
| 175 // OpMinusMinus, |
| 176 checkOperator("<","OpLess"); |
| 177 checkOperator("<=","OpLessEq"); |
| 178 checkOperator(">","OpGreater"); |
| 179 checkOperator(">=","OpGreaterEq"); |
| 180 //checkOperator("&=","OpAndEq"); |
| 181 //checkOperator("^=","OpXOrEq"); |
| 182 //checkOperator("|=","OpOrEq"); |
| 183 //checkOperator("%=","OpModEq"); |
| 184 checkOperator("&&","OpAnd"); |
| 185 checkOperator("||","OpOr"); |
| 186 checkOperator("&","OpBitAnd"); |
| 187 checkOperator("^","OpBitXOr"); |
| 188 checkOperator("|","OpBitOr"); |
| 189 checkOperator("<<","OpLShift"); |
| 190 checkOperator(">>","OpRShift"); |
| 191 checkOperator(">>>","OpURShift"); |
| 192 // OpIn, |
| 193 checkOperator("instanceof","OpInstanceOf"); |
| 194 |
| 195 // --------------------------------- |
| 196 var set_from_if_stmt = 4; |
| 197 try { |
| 198 if (throwex()) { |
| 199 set_from_if_stmt = 1; |
| 200 } |
| 201 } |
| 202 catch (e) { |
| 203 } |
| 204 shouldBe("set_from_if_stmt","4"); |
| 205 |
| 206 // --------------------------------- |
| 207 var set_from_if_else_stmt = 4; |
| 208 try { |
| 209 if (throwex()) { |
| 210 set_from_if_else_stmt = 1; |
| 211 } |
| 212 else { |
| 213 undefined; |
| 214 } |
| 215 } |
| 216 catch (e) { |
| 217 } |
| 218 shouldBe("set_from_if_else_stmt","4"); |
| 219 |
| 220 // --------------------------------- |
| 221 |
| 222 var set_from_else_in_if_else_stmt = 4; |
| 223 try { |
| 224 if (throwex()) { |
| 225 undefined; |
| 226 } |
| 227 else { |
| 228 set_from_else_in_if_else_stmt = 1; |
| 229 } |
| 230 } |
| 231 catch (e) { |
| 232 } |
| 233 shouldBe("set_from_else_in_if_else_stmt","4"); |
| 234 |
| 235 // --------------------------------- |
| 236 |
| 237 var comma_left = 4; |
| 238 try { |
| 239 comma_left = 1, throwex(); |
| 240 } |
| 241 catch (e) { |
| 242 } |
| 243 shouldBe("comma_left","1"); |
| 244 |
| 245 // --------------------------------- |
| 246 |
| 247 var comma_left = 4; |
| 248 try { |
| 249 throwex(), comma_left = 1; |
| 250 } |
| 251 catch (e) { |
| 252 } |
| 253 shouldBe("comma_left","4"); |
| 254 |
| 255 var vardecl_assign_throws = 4; |
| 256 try { |
| 257 var vardecl_assign_throws = throwex(); |
| 258 } |
| 259 catch (e) { |
| 260 } |
| 261 shouldBe("vardecl_assign_throws","4"); |
| 262 |
| 263 // --------------------------------- |
| 264 |
| 265 var var_assign_before_throw_run = false; |
| 266 function var_assign_before_throw() { |
| 267 var_assign_before_throw_run = true; |
| 268 return 1; |
| 269 } |
| 270 |
| 271 var var_assign_after_throw_run = false; |
| 272 function var_assign_after_throw() { |
| 273 var_assign_after_throw_run = true; |
| 274 return 1; |
| 275 } |
| 276 |
| 277 try { |
| 278 var var_assign1 = var_assign_before_throw(), |
| 279 var_assign2 = throwex(), |
| 280 var_assign1 = var_assign_before_throw(); |
| 281 } |
| 282 catch (e) { |
| 283 } |
| 284 shouldBe("var_assign_before_throw_run","true"); |
| 285 shouldBe("var_assign_after_throw_run","false"); |
| 286 |
| 287 // --------------------------------- |
| 288 |
| 289 var do_val = 4; |
| 290 try { |
| 291 do { |
| 292 do_val++; |
| 293 } |
| 294 while (throwex()); |
| 295 } |
| 296 catch (e) { |
| 297 } |
| 298 shouldBe("do_val","5"); |
| 299 |
| 300 // --------------------------------- |
| 301 var while_val = 4; |
| 302 try { |
| 303 while (throwex()) { |
| 304 while_val++; |
| 305 } |
| 306 } |
| 307 catch (e) { |
| 308 } |
| 309 shouldBe("while_val","4"); |
| 310 |
| 311 // --------------------------------- |
| 312 var for_val_part1_throw2 = 4; |
| 313 try { |
| 314 for (for_val_part1_throw2 = 1; throwex(); ) { |
| 315 } |
| 316 } |
| 317 catch (e) { |
| 318 } |
| 319 shouldBe("for_val_part1_throw2","1"); |
| 320 |
| 321 // --------------------------------- |
| 322 var for_val_part1_throw3 = 4; |
| 323 try { |
| 324 for (for_val_part1_throw3 = 1; ; throwex()) { |
| 325 } |
| 326 } |
| 327 catch (e) { |
| 328 } |
| 329 shouldBe("for_val_part1_throw3","1"); |
| 330 |
| 331 // --------------------------------- |
| 332 var for_val_part2_throw1 = 4; |
| 333 try { |
| 334 for (throwex(); for_val_part2_throw1 = 1; ) { |
| 335 } |
| 336 } |
| 337 catch (e) { |
| 338 } |
| 339 shouldBe("for_val_part2_throw1","4"); |
| 340 |
| 341 // --------------------------------- |
| 342 var for_val_part2_throw3 = 4; |
| 343 try { |
| 344 for (; for_val_part2_throw3 = 1; throwex()) { |
| 345 } |
| 346 } |
| 347 catch (e) { |
| 348 } |
| 349 shouldBe("for_val_part2_throw3","1"); |
| 350 |
| 351 // --------------------------------- |
| 352 var for_val_part3_throw1 = 4; |
| 353 try { |
| 354 for (throwex(); ; for_val_part3_throw1 = 1) { |
| 355 } |
| 356 } |
| 357 catch (e) { |
| 358 } |
| 359 shouldBe("for_val_part3_throw1","4"); |
| 360 |
| 361 // --------------------------------- |
| 362 var for_val_part3_throw2 = 4; |
| 363 try { |
| 364 for (; throwex(); for_val_part3_throw2 = 1) { |
| 365 } |
| 366 } |
| 367 catch (e) { |
| 368 } |
| 369 shouldBe("for_val_part3_throw2","4"); |
| 370 |
| 371 // --------------------------------- |
| 372 var for_val_part1_throwbody = 4; |
| 373 try { |
| 374 for (for_val_part1_throwbody = 1; ;) { |
| 375 throwex(); |
| 376 } |
| 377 } |
| 378 catch (e) { |
| 379 } |
| 380 shouldBe("for_val_part1_throwbody","1"); |
| 381 |
| 382 // --------------------------------- |
| 383 var for_val_part2_throwbody = 4; |
| 384 try { |
| 385 for (; for_val_part2_throwbody = 1; ) { |
| 386 throwex(); |
| 387 } |
| 388 } |
| 389 catch (e) { |
| 390 } |
| 391 shouldBe("for_val_part2_throwbody","1"); |
| 392 |
| 393 // --------------------------------- |
| 394 var for_val_part3_throwbody = 4; |
| 395 try { |
| 396 for (; ; for_val_part3_throwbody = 1) { |
| 397 throwex(); |
| 398 } |
| 399 } |
| 400 catch (e) { |
| 401 } |
| 402 shouldBe("for_val_part3_throwbody","4"); |
| 403 |
| 404 // --------------------------------- |
| 405 var forin_test_obj = new Object(); |
| 406 forin_test_obj.a = 1; |
| 407 forin_test_obj.b = 2; |
| 408 forin_test_obj.c = 3; |
| 409 var forin_count = 4; |
| 410 function forin_lexpr() { |
| 411 // if (forincount == 1); |
| 412 // throwex(); |
| 413 return new Object(); |
| 414 } |
| 415 try { |
| 416 for (throwex() in forin_test_obj) { |
| 417 forin_count++; |
| 418 } |
| 419 } |
| 420 catch (e) { |
| 421 } |
| 422 shouldBe("forin_count","4"); |
| 423 |
| 424 // --------------------------------- |
| 425 var set_inside_with_throw = 4; |
| 426 try { |
| 427 with (throwex()) { |
| 428 set_inside_with_throw = 1; |
| 429 } |
| 430 } |
| 431 catch (e) { |
| 432 } |
| 433 shouldBe("set_inside_with_throw","4"); |
| 434 |
| 435 // --------------------------------- |
| 436 var set_inside_with_cantconverttoobject = 4; |
| 437 try { |
| 438 with (undefined) { |
| 439 print("FAIL. This message should not be displayed"); |
| 440 set_inside_with_cantconverttoobject = 1; |
| 441 } |
| 442 } |
| 443 catch (e) { |
| 444 } |
| 445 shouldBe("set_inside_with_cantconverttoobject","4"); |
| 446 // ### test case, sw |
OLD | NEW |