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 ANY 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 ANY 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 ON 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 24description("KDE JS Test"); 25var global = this; 26function myfunc() { 27} 28function throwex() { 29 throw new Error("test exception"); 30} 31 32//--------------------------- 33var func_ret_with_ex_func = 4; 34try { 35 func_ret_with_ex_func = throwex()(); 36} 37catch (e) { 38} 39shouldBe("func_ret_with_ex_func", "4"); 40 41// --------------------------------- 42 43var func_ret_from_ex_throw_args = 4; 44try { 45 func_ret_from_ex_throw_args = Math.abs(throwex()); 46} 47catch (e) { 48} 49shouldBe("func_ret_from_ex_throw_args", "4"); 50 51// --------------------------------- 52 53var set_from_throw_func_args = 4; 54try { 55 throwex()(set_from_throw_func_args = 1); 56} 57catch (e) { 58} 59shouldBe("set_from_throw_func_args","4"); 60 61// --------------------------------- 62 63var set_from_func_throw_args = 4; 64try { 65 myfunc(throwex(), set_from_func_throw_args = 1); 66} 67catch (e) { 68} 69shouldBe("set_from_func_throw_args","4"); 70 71// --------------------------------- 72 73var set_from_before_func_throw_args = 4; 74try { 75 myfunc(set_from_before_func_throw_args = 1, throwex()); 76} 77catch (e) { 78} 79shouldBe("set_from_before_func_throw_args","1"); 80 81// --------------------------------- 82 83// ### move to function.js 84var function_param_order = ""; 85function aparam() { 86 function_param_order += "a"; 87} 88function bparam() { 89 function_param_order += "b"; 90} 91function cparam() { 92 function_param_order += "c"; 93} 94myfunc(aparam(),bparam(),cparam()); 95shouldBe("function_param_order","'abc'"); 96 97// --------------------------------- 98// ### move to function.js 99var new_param_order = ""; 100function anewparam() { 101 new_param_order += "a"; 102} 103function bnewparam() { 104 new_param_order += "b"; 105} 106function cnewparam() { 107 new_param_order += "c"; 108} 109new myfunc(anewparam(),bnewparam(),cnewparam()); 110shouldBe("new_param_order","'abc'"); 111 112// --------------------------------- 113// ### move to function.js 114var elision_param_order = ""; 115function aelision() { 116 elision_param_order += "a"; 117} 118function belision() { 119 elision_param_order += "b"; 120} 121function celision() { 122 elision_param_order += "c"; 123} 124[aelision(),belision(),celision()]; 125shouldBe("elision_param_order","'abc'"); 126 127// --------------------------------- 128// ### move to function.js 129var comma_order = ""; 130function acomma() { 131 comma_order += "a"; 132} 133function bcomma() { 134 comma_order += "b"; 135} 136function ccomma() { 137 comma_order += "c"; 138} 139acomma(),bcomma(),ccomma(); 140shouldBe("comma_order","'abc'"); 141 142// --------------------------------- 143 144function 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 165checkOperator("==","OpEqEq"); 166checkOperator("!=","OpNotEq"); 167checkOperator("===","OpStrEq"); 168checkOperator("!==","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, 176checkOperator("<","OpLess"); 177checkOperator("<=","OpLessEq"); 178checkOperator(">","OpGreater"); 179checkOperator(">=","OpGreaterEq"); 180//checkOperator("&=","OpAndEq"); 181//checkOperator("^=","OpXOrEq"); 182//checkOperator("|=","OpOrEq"); 183//checkOperator("%=","OpModEq"); 184checkOperator("&&","OpAnd"); 185checkOperator("||","OpOr"); 186checkOperator("&","OpBitAnd"); 187checkOperator("^","OpBitXOr"); 188checkOperator("|","OpBitOr"); 189checkOperator("<<","OpLShift"); 190checkOperator(">>","OpRShift"); 191checkOperator(">>>","OpURShift"); 192// OpIn, 193checkOperator("instanceof","OpInstanceOf"); 194 195// --------------------------------- 196var set_from_if_stmt = 4; 197try { 198 if (throwex()) { 199 set_from_if_stmt = 1; 200 } 201} 202catch (e) { 203} 204shouldBe("set_from_if_stmt","4"); 205 206// --------------------------------- 207var set_from_if_else_stmt = 4; 208try { 209 if (throwex()) { 210 set_from_if_else_stmt = 1; 211 } 212 else { 213 undefined; 214 } 215} 216catch (e) { 217} 218shouldBe("set_from_if_else_stmt","4"); 219 220// --------------------------------- 221 222var set_from_else_in_if_else_stmt = 4; 223try { 224 if (throwex()) { 225 undefined; 226 } 227 else { 228 set_from_else_in_if_else_stmt = 1; 229 } 230} 231catch (e) { 232} 233shouldBe("set_from_else_in_if_else_stmt","4"); 234 235// --------------------------------- 236 237var comma_left = 4; 238try { 239 comma_left = 1, throwex(); 240} 241catch (e) { 242} 243shouldBe("comma_left","1"); 244 245// --------------------------------- 246 247var comma_left = 4; 248try { 249 throwex(), comma_left = 1; 250} 251catch (e) { 252} 253shouldBe("comma_left","4"); 254 255var vardecl_assign_throws = 4; 256try { 257 var vardecl_assign_throws = throwex(); 258} 259catch (e) { 260} 261shouldBe("vardecl_assign_throws","4"); 262 263// --------------------------------- 264 265var var_assign_before_throw_run = false; 266function var_assign_before_throw() { 267 var_assign_before_throw_run = true; 268 return 1; 269} 270 271var var_assign_after_throw_run = false; 272function var_assign_after_throw() { 273 var_assign_after_throw_run = true; 274 return 1; 275} 276 277try { 278 var var_assign1 = var_assign_before_throw(), 279 var_assign2 = throwex(), 280 var_assign1 = var_assign_before_throw(); 281} 282catch (e) { 283} 284shouldBe("var_assign_before_throw_run","true"); 285shouldBe("var_assign_after_throw_run","false"); 286 287// --------------------------------- 288 289var do_val = 4; 290try { 291 do { 292 do_val++; 293 } 294 while (throwex()); 295} 296catch (e) { 297} 298shouldBe("do_val","5"); 299 300// --------------------------------- 301var while_val = 4; 302try { 303 while (throwex()) { 304 while_val++; 305 } 306} 307catch (e) { 308} 309shouldBe("while_val","4"); 310 311// --------------------------------- 312var for_val_part1_throw2 = 4; 313try { 314 for (for_val_part1_throw2 = 1; throwex(); ) { 315 } 316} 317catch (e) { 318} 319shouldBe("for_val_part1_throw2","1"); 320 321// --------------------------------- 322var for_val_part1_throw3 = 4; 323try { 324 for (for_val_part1_throw3 = 1; ; throwex()) { 325 } 326} 327catch (e) { 328} 329shouldBe("for_val_part1_throw3","1"); 330 331// --------------------------------- 332var for_val_part2_throw1 = 4; 333try { 334 for (throwex(); for_val_part2_throw1 = 1; ) { 335 } 336} 337catch (e) { 338} 339shouldBe("for_val_part2_throw1","4"); 340 341// --------------------------------- 342var for_val_part2_throw3 = 4; 343try { 344 for (; for_val_part2_throw3 = 1; throwex()) { 345 } 346} 347catch (e) { 348} 349shouldBe("for_val_part2_throw3","1"); 350 351// --------------------------------- 352var for_val_part3_throw1 = 4; 353try { 354 for (throwex(); ; for_val_part3_throw1 = 1) { 355 } 356} 357catch (e) { 358} 359shouldBe("for_val_part3_throw1","4"); 360 361// --------------------------------- 362var for_val_part3_throw2 = 4; 363try { 364 for (; throwex(); for_val_part3_throw2 = 1) { 365 } 366} 367catch (e) { 368} 369shouldBe("for_val_part3_throw2","4"); 370 371// --------------------------------- 372var for_val_part1_throwbody = 4; 373try { 374 for (for_val_part1_throwbody = 1; ;) { 375 throwex(); 376 } 377} 378catch (e) { 379} 380shouldBe("for_val_part1_throwbody","1"); 381 382// --------------------------------- 383var for_val_part2_throwbody = 4; 384try { 385 for (; for_val_part2_throwbody = 1; ) { 386 throwex(); 387 } 388} 389catch (e) { 390} 391shouldBe("for_val_part2_throwbody","1"); 392 393// --------------------------------- 394var for_val_part3_throwbody = 4; 395try { 396 for (; ; for_val_part3_throwbody = 1) { 397 throwex(); 398 } 399} 400catch (e) { 401} 402shouldBe("for_val_part3_throwbody","4"); 403 404// --------------------------------- 405var set_inside_with_throw = 4; 406try { 407 with (throwex()) { 408 set_inside_with_throw = 1; 409 } 410} 411catch (e) { 412} 413shouldBe("set_inside_with_throw","4"); 414 415// --------------------------------- 416var set_inside_with_cantconverttoobject = 4; 417try { 418 with (undefined) { 419 print("FAIL. This message should not be displayed"); 420 set_inside_with_cantconverttoobject = 1; 421 } 422} 423catch (e) { 424} 425shouldBe("set_inside_with_cantconverttoobject","4"); 426// ### test case, sw 427