1/* 2 * Copyright 2008 Jacek Caban for CodeWeavers 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 */ 18 19var tmp; 20 21ok(true, "true is not true?"); 22ok(!false, "!false is not true"); 23ok(!undefined, "!undefined is not true"); 24ok(!null, "!null is not true"); 25ok(!0, "!0 is not true"); 26ok(!0.0, "!0.0 is not true"); 27 28ok(1 === 1, "1 === 1 is false"); 29ok(!(1 === 2), "!(1 === 2) is false"); 30ok(1.0 === 1, "1.0 === 1 is false"); 31ok("abc" === "abc", "\"abc\" === \"abc\" is false"); 32ok(true === true, "true === true is false"); 33ok(null === null, "null === null is false"); 34ok(undefined === undefined, "undefined === undefined is false"); 35ok(!(undefined === null), "!(undefined === null) is false"); 36ok(1E0 === 1, "1E0 === 1 is false"); 37ok(1000000*1000000 === 1000000000000, "1000000*1000000 === 1000000000000 is false"); 38ok(8.64e15 === 8640000000000000, "8.64e15 !== 8640000000000000"); 39ok(1e2147483648 === Infinity, "1e2147483648 !== Infinity"); 40 41ok(00 === 0, "00 != 0"); 42ok(010 === 8, "010 != 8"); 43ok(077 === 63, "077 != 63"); 44ok(080 === 80, "080 != 80"); 45ok(090 === 90, "090 != 90"); 46ok(018 === 18, "018 != 18"); 47tmp = 07777777777777777777777; 48ok(typeof(tmp) === "number" && tmp > 0xffffffff, "tmp = " + tmp); 49tmp = 07777777779777777777777; 50ok(typeof(tmp) === "number" && tmp > 0xffffffff, "tmp = " + tmp); 51 52ok(1 !== 2, "1 !== 2 is false"); 53ok(null !== undefined, "null !== undefined is false"); 54 55ok(1 == 1, "1 == 1 is false"); 56ok(!(1 == 2), "!(1 == 2) is false"); 57ok(1.0 == 1, "1.0 == 1 is false"); 58ok("abc" == "abc", "\"abc\" == \"abc\" is false"); 59ok(true == true, "true == true is false"); 60ok(null == null, "null == null is false"); 61ok(undefined == undefined, "undefined == undefined is false"); 62ok(undefined == null, "undefined == null is false"); 63ok(true == 1, "true == 1 is false"); 64ok(!(true == 2), "true == 2"); 65ok(0 == false, "0 == false is false"); 66 67ok(1 != 2, "1 != 2 is false"); 68ok(false != 1, "false != 1 is false"); 69 70ok(this === test, "this !== test"); 71eval('ok(this === test, "this !== test");'); 72 73var trueVar = true; 74ok(trueVar, "trueVar is not true"); 75 76ok(ScriptEngine.length === 0, "ScriptEngine.length is not 0"); 77 78function testFunc1(x, y) { 79 ok(this !== undefined, "this is undefined"); 80 ok(x === true, "x is not true"); 81 ok(y === "test", "y is not \"test\""); 82 ok(arguments.length === 2, "arguments.length is not 2"); 83 ok(arguments["0"] === true, "arguments[0] is not true"); 84 ok(arguments["1"] === "test", "arguments[1] is not \"test\""); 85 ok(arguments.callee === testFunc1, "arguments.calee !== testFunc1"); 86 ok(testFunc1.arguments === arguments, "testFunc1.arguments = " + testFunc1.arguments); 87 88 x = false; 89 ok(arguments[0] === false, "arguments[0] is not false"); 90 arguments[1] = "x"; 91 ok(y === "x", "y = " + y); 92 ok(arguments[1] === "x", "arguments[1] = " + arguments[1]); 93 94 ok(arguments["0x0"] === undefined, "arguments['0x0'] = " + arguments["0x0"]); 95 ok(arguments["x"] === undefined, "arguments['x'] = " + arguments["x"]); 96 97 ok(this === test, "this !== test"); 98 eval('ok(this === test, "this !== test");'); 99 100 tmp = delete arguments; 101 ok(tmp === false, "arguments deleted"); 102 ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments)); 103 104 x = 2; 105 ok(x === 2, "x = " + x); 106 ok(arguments[0] === 2, "arguments[0] = " + arguments[0]); 107 108 return true; 109} 110 111ok(testFunc1.length === 2, "testFunc1.length is not 2"); 112ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments); 113 114ok(Object.prototype !== undefined, "Object.prototype is undefined"); 115ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined"); 116ok(String.prototype !== undefined, "String.prototype is undefined"); 117ok(Array.prototype !== undefined, "Array.prototype is undefined"); 118ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined"); 119ok(Number.prototype !== undefined, "Number.prototype is undefined"); 120ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined"); 121ok(Math !== undefined, "Math is undefined"); 122ok(Math.prototype === undefined, "Math.prototype is not undefined"); 123ok(Function.prototype !== undefined, "Function.prototype is undefined"); 124ok(Function.prototype.prototype === undefined, "Function.prototype.prototype is not undefined"); 125ok(Date.prototype !== undefined, "Date.prototype is undefined"); 126ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined"); 127 128function testConstructor(constr, name, inst) { 129 ok(constr.prototype.constructor === constr, name + ".prototype.constructor !== " + name); 130 ok(constr.prototype.hasOwnProperty("constructor"), name + ".prototype.hasOwnProperty('constructor')"); 131 132 if(!inst) 133 inst = new constr(); 134 135 ok(inst.constructor === constr, "(new " + name + "()).constructor !== " + name); 136 ok(!inst.hasOwnProperty("constructor"), "(new " + name + "()).hasOwnProperty('constructor')"); 137} 138 139testConstructor(Object, "Object"); 140testConstructor(String, "String"); 141testConstructor(Array, "Array"); 142testConstructor(Boolean, "Boolean"); 143testConstructor(Number, "Number"); 144testConstructor(RegExp, "RegExp", /x/); 145testConstructor(Function, "Function"); 146testConstructor(Date, "Date"); 147testConstructor(VBArray, "VBArray", new VBArray(createArray())); 148testConstructor(Error, "Error"); 149testConstructor(EvalError, "EvalError"); 150testConstructor(RangeError, "RangeError"); 151testConstructor(ReferenceError, "ReferenceError"); 152testConstructor(RegExpError, "RegExpError"); 153testConstructor(SyntaxError, "SyntaxError"); 154testConstructor(TypeError, "TypeError"); 155testConstructor(URIError, "URIError"); 156 157Function.prototype.test = true; 158ok(testFunc1.test === true, "testFunc1.test !== true"); 159ok(Function.test === true, "Function.test !== true"); 160 161ok(typeof(0) === "number", "typeof(0) is not number"); 162ok(typeof(1.5) === "number", "typeof(1.5) is not number"); 163ok(typeof("abc") === "string", "typeof(\"abc\") is not string"); 164ok(typeof("") === "string", "typeof(\"\") is not string"); 165ok(typeof(true) === "boolean", "typeof(true) is not boolean"); 166ok(typeof(null) === "object", "typeof(null) is not object"); 167ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined"); 168ok(typeof(Math) === "object", "typeof(Math) is not object"); 169ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object"); 170ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function"); 171ok(typeof(String) === "function", "typeof(String) is not function"); 172ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function"); 173ok(typeof(this) === "object", "typeof(this) is not object"); 174ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist)); 175tmp = typeof((new Object()).doesnotexist); 176ok(tmp === "undefined", "typeof((new Object).doesnotexist = " + tmp); 177tmp = typeof(testObj.onlyDispID); 178ok(tmp === "unknown", "typeof(testObj.onlyDispID) = " + tmp); 179 180ok(testFunc1(true, "test") === true, "testFunc1 not returned true"); 181 182ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments); 183 184(tmp) = 3; 185ok(tmp === 3, "tmp = " + tmp); 186 187function testRecFunc(x) { 188 ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments); 189 if(x) { 190 testRecFunc(false); 191 ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments); 192 ok(testRecFunc.arguments[0] === true, "testRecFunc.arguments.x = " + testRecFunc.arguments[0]); 193 } 194} 195 196testRecFunc.arguments = 5; 197ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments); 198testRecFunc(true); 199ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments); 200 201function argumentsTest() { 202 var save = arguments; 203 with({arguments: 1}) { 204 ok(arguments === 1, "arguments = " + arguments); 205 (function() { 206 ok(argumentsTest.arguments === save, "unexpected argumentsTest.arguments"); 207 })(); 208 } 209 eval('ok(arguments === save, "unexpected arguments");'); 210 [1,2].sort(function() { 211 ok(argumentsTest.arguments === save, "unexpected argumentsTest.arguments"); 212 return 1; 213 }); 214} 215 216argumentsTest(); 217 218// arguments object detached from its execution context 219(function() { 220 var args, get_x, set_x; 221 222 function test_args(detached) { 223 ok(args[0] === 1, "args[0] = " + args[0]); 224 set_x(2); 225 ok(args[0] === (detached ? 1 : 2), "args[0] = " + args[0] + " expected " + (detached ? 1 : 2)); 226 args[0] = 3; 227 ok(get_x() === (detached ? 2 : 3), "get_x() = " + get_x()); 228 ok(args[0] === 3, "args[0] = " + args[0]); 229 } 230 231 (function(x) { 232 args = arguments; 233 get_x = function() { return x; }; 234 set_x = function(v) { x = v; }; 235 236 test_args(false); 237 x = 1; 238 })(1); 239 240 test_args(true); 241})(); 242 243// arguments is a regular variable, it may be overwritten 244(function() { 245 ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments)); 246 arguments = 1; 247 ok(arguments === 1, "arguments = " + arguments); 248})(); 249 250(function callAsExprTest() { 251 ok(callAsExprTest.arguments === null, "callAsExprTest.arguments = " + callAsExprTest.arguments); 252})(1,2); 253 254tmp = (function() {1;})(); 255ok(tmp === undefined, "tmp = " + tmp); 256tmp = eval("1;"); 257ok(tmp === 1, "tmp = " + tmp); 258tmp = eval("1,2;"); 259ok(tmp === 2, "tmp = " + tmp); 260tmp = eval("testNoRes(),2;"); 261ok(tmp === 2, "tmp = " + tmp); 262tmp = eval("if(true) {3}"); 263ok(tmp === 3, "tmp = " + tmp); 264eval("testRes(); testRes()"); 265tmp = eval("3; if(false) {4;} else {};;;") 266ok(tmp === 3, "tmp = " + tmp); 267tmp = eval("try { 1; } finally { 2; }") 268ok(tmp === 2, "tmp = " + tmp); 269 270testNoRes(); 271testRes() && testRes(); 272testNoRes(), testNoRes(); 273 274(function() { 275 eval("var x=1;"); 276 ok(x === 1, "x = " + x); 277})(); 278 279(function() { 280 var e = eval; 281 var r = e(1); 282 ok(r === 1, "r = " + r); 283 (function(x, a) { x(a); })(eval, "2"); 284})(); 285 286(function(r) { 287 r = eval("1"); 288 ok(r === 1, "r = " + r); 289 (function(x, a) { x(a); })(eval, "2"); 290})(); 291 292tmp = (function(){ return testNoRes(), testRes();})(); 293 294var f1, f2; 295 296ok(funcexpr() == 2, "funcexpr() = " + funcexpr()); 297 298f1 = function funcexpr() { return 1; } 299ok(f1 != funcexpr, "f1 == funcexpr"); 300ok(f1() === 1, "f1() = " + f1()); 301 302f2 = function funcexpr() { return 2; } 303ok(f2 != funcexpr, "f2 != funcexpr"); 304ok(f2() === 2, "f2() = " + f2()); 305 306f1 = null; 307for(i = 0; i < 3; i++) { 308 f2 = function funcexpr2() {}; 309 ok(f1 != f2, "f1 == f2"); 310 f1 = f2; 311} 312 313f1 = null; 314for(i = 0; i < 3; i++) { 315 f2 = function() {}; 316 ok(f1 != f2, "f1 == f2"); 317 f1 = f2; 318} 319 320(function() { 321 ok(infuncexpr() == 2, "infuncexpr() = " + infuncexpr()); 322 323 f1 = function infuncexpr() { return 1; } 324 ok(f1 != funcexpr, "f1 == funcexpr"); 325 ok(f1() === 1, "f1() = " + f1()); 326 327 f2 = function infuncexpr() { return 2; } 328 ok(f2 != funcexpr, "f2 != funcexpr"); 329 ok(f2() === 2, "f2() = " + f2()); 330 331 f1 = null; 332 for(i = 0; i < 3; i++) { 333 f2 = function infuncexpr2() {}; 334 ok(f1 != f2, "f1 == f2"); 335 f1 = f2; 336 } 337 338 f1 = null; 339 for(i = 0; i < 3; i++) { 340 f2 = function() {}; 341 ok(f1 != f2, "f1 == f2"); 342 f1 = f2; 343 } 344})(); 345 346var obj1 = new Object(); 347ok(typeof(obj1) === "object", "typeof(obj1) is not object"); 348ok(obj1.constructor === Object, "unexpected obj1.constructor"); 349obj1.test = true; 350obj1.func = function () { 351 ok(this === obj1, "this is not obj1"); 352 ok(this.test === true, "this.test is not true"); 353 ok(arguments.length === 1, "arguments.length is not 1"); 354 ok(arguments["0"] === true, "arguments[0] is not true"); 355 ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee)); 356 357 return "test"; 358}; 359 360ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\""); 361 362function testConstr1() { 363 this.var1 = 1; 364 365 ok(this !== undefined, "this is undefined"); 366 ok(arguments.length === 1, "arguments.length is not 1"); 367 ok(arguments["0"] === true, "arguments[0] is not 1"); 368 ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1"); 369 370 return false; 371} 372 373testConstr1.prototype.pvar = 1; 374ok(testConstr1.prototype.constructor === testConstr1, "testConstr1.prototype.constructor !== testConstr1"); 375 376var obj2 = new testConstr1(true); 377ok(typeof(obj2) === "object", "typeof(obj2) is not object"); 378ok(obj2.constructor === testConstr1, "unexpected obj2.constructor"); 379ok(obj2.pvar === 1, "obj2.pvar is not 1"); 380ok(!obj2.hasOwnProperty('constructor'), "obj2.hasOwnProperty('constructor')"); 381 382testConstr1.prototype.pvar = 2; 383ok(obj2.pvar === 2, "obj2.pvar is not 2"); 384 385obj2.pvar = 3; 386testConstr1.prototype.pvar = 1; 387ok(obj2.pvar === 3, "obj2.pvar is not 3"); 388 389obj1 = new Object(); 390function testConstr3() { 391 return obj1; 392} 393 394obj2 = new testConstr3(); 395ok(obj1 === obj2, "obj1 != obj2"); 396 397function testConstr4() { 398 return 2; 399} 400 401obj2 = new testConstr3(); 402ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2)); 403 404var obj3 = new Object; 405ok(typeof(obj3) === "object", "typeof(obj3) is not object"); 406 407(function() { 408 ok(typeof(func) === "function", "typeof(func) = " + typeof(func)); 409 function func() {} 410 ok(typeof(func) === "function", "typeof(func) = " + typeof(func)); 411 func = 0; 412 ok(typeof(func) === "number", "typeof(func) = " + typeof(func)); 413})(); 414 415(function(f) { 416 ok(typeof(f) === "function", "typeof(f) = " + typeof(f)); 417 function f() {}; 418 ok(typeof(f) === "function", "typeof(f) = " + typeof(f)); 419})(1); 420 421for(var iter in "test") 422 ok(false, "unexpected forin call, test = " + iter); 423 424for(var iter in null) 425 ok(false, "unexpected forin call, test = " + iter); 426 427for(var iter in false) 428 ok(false, "unexpected forin call, test = " + iter); 429 430for(var iter in pureDisp) 431 ok(false, "unexpected forin call in pureDisp object"); 432 433tmp = new Object(); 434ok(!tmp.nonexistent, "!tmp.nonexistent = " + !tmp.nonexistent); 435ok(!("nonexistent" in tmp), "nonexistent is in tmp after '!' expression") 436 437tmp = new Object(); 438ok((~tmp.nonexistent) === -1, "!tmp.nonexistent = " + ~tmp.nonexistent); 439ok(!("nonexistent" in tmp), "nonexistent is in tmp after '~' expression") 440 441tmp = new Object(); 442ok(isNaN(+tmp.nonexistent), "!tmp.nonexistent = " + (+tmp.nonexistent)); 443ok(!("nonexistent" in tmp), "nonexistent is in tmp after '+' expression") 444 445tmp = new Object(); 446tmp[tmp.nonexistent]; 447ok(!("nonexistent" in tmp), "nonexistent is in tmp after array expression") 448 449tmp = 0; 450if(true) 451 tmp = 1; 452else 453 ok(false, "else evaluated"); 454ok(tmp === 1, "tmp !== 1, if not evaluated?"); 455 456tmp = 0; 457if(1 === 0) 458 ok(false, "if evaluated"); 459else 460 tmp = 1; 461ok(tmp === 1, "tmp !== 1, if not evaluated?"); 462 463if(false) 464 ok(false, "if(false) evaluated"); 465 466tmp = 0; 467if(true) 468 tmp = 1; 469ok(tmp === 1, "tmp !== 1, if(true) not evaluated?"); 470 471if(false) { 472}else { 473} 474 475var obj3 = { prop1: 1, prop2: typeof(false) }; 476ok(obj3.prop1 === 1, "obj3.prop1 is not 1"); 477ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\""); 478ok(obj3.constructor === Object, "unexpected obj3.constructor"); 479 480{ 481 var blockVar = 1; 482 blockVar = 2; 483} 484ok(blockVar === 2, "blockVar !== 2"); 485 486ok((true ? 1 : 2) === 1, "conditional expression true is not 1"); 487ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2"); 488 489ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY"); 490ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL"); 491ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4"); 492ok(getVT(0.5) === "VT_R8", "getVT(0.5) is not VT_R8"); 493ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR"); 494ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH"); 495ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL"); 496 497tmp = 2+2; 498ok(tmp === 4, "2+2 !== 4"); 499ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4"); 500 501tmp = 2+2.5; 502ok(tmp === 4.5, "2+2.5 !== 4.5"); 503ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8"); 504 505tmp = 1.5+2.5; 506ok(tmp === 4, "1.4+2.5 !== 4"); 507ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4"); 508 509tmp = 4-2; 510ok(tmp === 2, "4-2 !== 2"); 511ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4"); 512 513tmp = 4.5-2; 514ok(tmp === 2.5, "4.5-2 !== 2.5"); 515ok(getVT(tmp) === "VT_R8", "getVT(4.5-2) !== VT_R8"); 516 517tmp = -2; 518ok(tmp === 0-2, "-2 !== 0-2"); 519ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4"); 520 521tmp = 2*3; 522ok(tmp === 6, "2*3 !== 6"); 523ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4"); 524 525tmp = 2*3.5; 526ok(tmp === 7, "2*3.5 !== 7"); 527ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4"); 528 529tmp = 2.5*3.5; 530/* FIXME: the parser loses precision */ 531/* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */ 532ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75"); 533ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8"); 534 535tmp = 2*.5; 536ok(tmp === 1, "2*.5 !== 1"); 537ok(getVT(tmp) == "VT_I4", "getVT(2*.5) !== VT_I4"); 538 539tmp = 4/2; 540ok(tmp === 2, "4/2 !== 2"); 541ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4"); 542 543tmp = 4.5/1.5; 544ok(tmp === 3, "4.5/1.5 !== 3"); 545ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4"); 546 547tmp = 3/2; 548ok(tmp === 1.5, "3/2 !== 1.5"); 549ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8"); 550 551tmp = 3%2; 552ok(tmp === 1, "3%2 = " + tmp); 553 554tmp = 4%2; 555ok(tmp ===0, "4%2 = " + tmp); 556 557tmp = 3.5%1.5; 558ok(tmp === 0.5, "3.5%1.5 = " + tmp); 559 560tmp = 3%true; 561ok(tmp === 0, "3%true = " + tmp); 562 563tmp = "ab" + "cd"; 564ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\""); 565 566tmp = 1; 567ok((tmp += 1) === 2, "tmp += 1 !== 2"); 568ok(tmp === 2, "tmp !== 2"); 569 570tmp = 2; 571ok((tmp -= 1) === 1, "tmp -= 1 !== 1"); 572ok(tmp === 1, "tmp !=== 1"); 573 574tmp = 2; 575ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3"); 576ok(tmp === 3, "tmp !=== 3"); 577 578tmp = 5; 579ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5"); 580ok(tmp === 2.5, "tmp !=== 2.5"); 581 582tmp = 3; 583ok((tmp %= 2) === 1, "tmp %= 2 !== 1"); 584ok(tmp === 1, "tmp !== 1"); 585 586tmp = 8; 587ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16"); 588 589tmp = 8; 590ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4"); 591 592tmp = 8; 593ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4"); 594 595tmp = 3 || ok(false, "second or expression called"); 596ok(tmp === 3, "3 || (...) is not 3"); 597 598tmp = false || 2; 599ok(tmp === 2, "false || 2 is not 2"); 600 601tmp = 0 && ok(false, "second and expression called"); 602ok(tmp === 0, "0 && (...) is not 0"); 603 604tmp = true && "test"; 605ok(tmp === "test", "true && \"test\" is not \"test\""); 606 607tmp = true && 0; 608ok(tmp === 0, "true && 0 is not 0"); 609 610tmp = 3 | 4; 611ok(tmp === 7, "3 | 4 !== 7"); 612ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp)); 613 614tmp = 3.5 | 0; 615ok(tmp === 3, "3.5 | 0 !== 3"); 616ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp)); 617 618tmp = -3.5 | 0; 619ok(tmp === -3, "-3.5 | 0 !== -3"); 620ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp)); 621 622tmp = 0 | NaN; 623ok(tmp === 0, "0 | NaN = " + tmp); 624 625tmp = 0 | Infinity; 626ok(tmp === 0, "0 | NaN = " + tmp); 627 628tmp = 0 | (-Infinity); 629ok(tmp === 0, "0 | NaN = " + tmp); 630 631tmp = 10; 632ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26"); 633ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp)); 634 635tmp = 3 & 5; 636ok(tmp === 1, "3 & 5 !== 1"); 637ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp)); 638 639tmp = 3.5 & 0xffff; 640ok(tmp === 3, "3.5 & 0xffff !== 3 "); 641ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp)); 642 643tmp = (-3.5) & 0xffffffff; 644ok(tmp === -3, "-3.5 & 0xffff !== -3"); 645ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp)); 646 647tmp = 2 << 3; 648ok(tmp === 16, "2 << 3 = " + tmp); 649 650tmp = 2 << 35; 651ok(tmp === 16, "2 << 35 = " + tmp); 652 653tmp = 8 >> 2; 654ok(tmp === 2, "8 >> 2 = " + tmp); 655 656tmp = -64 >> 4; 657ok(tmp === -4, "-64 >> 4 = " + tmp); 658 659tmp = 8 >>> 2; 660ok(tmp === 2, "8 >> 2 = " + tmp); 661 662tmp = -64 >>> 4; 663ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp); 664 665tmp = 4 >>> NaN; 666ok(tmp === 4, "4 >>> NaN = " + tmp); 667 668tmp = 10; 669ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8"); 670ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp)); 671 672tmp = 0xf0f0^0xff00; 673ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0"); 674ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp)); 675 676tmp = 5; 677ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6"); 678ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp)); 679 680tmp = ~1; 681ok(tmp === -2, "~1 !== -2"); 682ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp)); 683 684ok((3,4) === 4, "(3,4) !== 4"); 685 686ok(+3 === 3, "+3 !== 3"); 687ok(+true === 1, "+true !== 1"); 688ok(+false === 0, "+false !== 0"); 689ok(+null === 0, "+null !== 0"); 690ok(+"0" === 0, "+'0' !== 0"); 691ok(+"3" === 3, "+'3' !== 3"); 692ok(+"-3" === -3, "+'-3' !== -3"); 693ok(+"0xff" === 255, "+'0xff' !== 255"); 694ok(+"3e3" === 3000, "+'3e3' !== 3000"); 695 696tmp = new Number(1); 697ok(+tmp === 1, "+(new Number(1)) = " + (+tmp)); 698ok(tmp.constructor === Number, "unexpected tmp.constructor"); 699tmp = new String("1"); 700ok(+tmp === 1, "+(new String('1')) = " + (+tmp)); 701ok(tmp.constructor === String, "unexpected tmp.constructor"); 702 703ok("" + 0 === "0", "\"\" + 0 !== \"0\""); 704ok("" + 123 === "123", "\"\" + 123 !== \"123\""); 705ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\""); 706ok("" + null === "null", "\"\" + null !== \"null\""); 707ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\""); 708ok("" + true === "true", "\"\" + true !== \"true\""); 709ok("" + false === "false", "\"\" + false !== \"false\""); 710ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5); 711ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432)); 712 713ok(1 < 3.4, "1 < 3.4 failed"); 714ok(!(3.4 < 1), "3.4 < 1"); 715ok("abc" < "abcd", "abc < abcd failed"); 716ok("abcd" < "abce", "abce < abce failed"); 717ok("" < "x", "\"\" < \"x\" failed"); 718ok(!(0 < 0), "0 < 0"); 719 720ok(1 <= 3.4, "1 <= 3.4 failed"); 721ok(!(3.4 <= 1), "3.4 <= 1"); 722ok("abc" <= "abcd", "abc <= abcd failed"); 723ok("abcd" <= "abce", "abce <= abce failed"); 724ok("" <= "x", "\"\" <= \"x\" failed"); 725ok(0 <= 0, "0 <= 0 failed"); 726 727ok(3.4 > 1, "3.4 > 1 failed"); 728ok(!(1 > 3.4), "1 > 3.4"); 729ok("abcd" > "abc", "abc > abcd failed"); 730ok("abce" > "abcd", "abce > abce failed"); 731ok("x" > "", "\"x\" > \"\" failed"); 732ok(!(0 > 0), "0 > 0"); 733 734ok(3.4 >= 1, "3.4 >= 1 failed"); 735ok(!(1 >= 3.4), "1 >= 3.4"); 736ok("abcd" >= "abc", "abc >= abcd failed"); 737ok("abce" >= "abcd", "abce >= abce failed"); 738ok("x" >= "", "\"x\" >= \"\" failed"); 739ok(0 >= 0, "0 >= 0"); 740 741tmp = 1; 742ok(++tmp === 2, "++tmp (1) is not 2"); 743ok(tmp === 2, "incremented tmp is not 2"); 744ok(--tmp === 1, "--tmp (2) is not 1"); 745ok(tmp === 1, "decremented tmp is not 1"); 746ok(tmp++ === 1, "tmp++ (1) is not 1"); 747ok(tmp === 2, "incremented tmp(1) is not 2"); 748ok(tmp-- === 2, "tmp-- (2) is not 2"); 749ok(tmp === 1, "decremented tmp is not 1"); 750 751tmp = new Object(); 752tmp.iii++; 753ok(isNaN(tmp.iii), "tmp.iii = " + tmp.iii); 754 755String.prototype.test = true; 756ok("".test === true, "\"\".test is not true"); 757 758Boolean.prototype.test = true; 759ok(true.test === true, "true.test is not true"); 760 761Number.prototype.test = true; 762ok((0).test === true, "(0).test is not true"); 763ok((0.5).test === true, "(0.5).test is not true"); 764 765var state = ""; 766try { 767 ok(state === "", "try: state = " + state); 768 state = "try"; 769}catch(ex) { 770 ok(false, "unexpected catch"); 771} 772ok(state === "try", "state = " + state + " expected try"); 773 774state = ""; 775try { 776 ok(state === "", "try: state = " + state); 777 state = "try"; 778}finally { 779 ok(state === "try", "finally: state = " + state); 780 state = "finally"; 781} 782ok(state === "finally", "state = " + state + " expected finally"); 783 784state = ""; 785try { 786 try { 787 throw 0; 788 }finally { 789 state = "finally"; 790 } 791}catch(e) { 792 ok(state === "finally", "state = " + state + " expected finally"); 793 state = "catch"; 794} 795ok(state === "catch", "state = " + state + " expected catch"); 796 797try { 798 try { 799 throw 0; 800 }finally { 801 throw 1; 802 } 803}catch(e) { 804 ok(e === 1, "e = " + e); 805} 806 807state = ""; 808try { 809 ok(state === "", "try: state = " + state); 810 state = "try"; 811}catch(ex) { 812 ok(false, "unexpected catch"); 813}finally { 814 ok(state === "try", "finally: state = " + state); 815 state = "finally"; 816} 817ok(state === "finally", "state = " + state + " expected finally"); 818 819var state = ""; 820try { 821 ok(state === "", "try: state = " + state); 822 state = "try"; 823 throw "except"; 824}catch(ex) { 825 ok(state === "try", "catch: state = " + state); 826 ok(ex === "except", "ex is not \"except\""); 827 state = "catch"; 828} 829ok(state === "catch", "state = " + state + " expected catch"); 830 831var state = ""; 832try { 833 ok(state === "", "try: state = " + state); 834 state = "try"; 835 throw true; 836}catch(ex) { 837 ok(state === "try", "catch: state = " + state); 838 ok(ex === true, "ex is not true"); 839 state = "catch"; 840}finally { 841 ok(state === "catch", "finally: state = " + state); 842 state = "finally"; 843} 844ok(state === "finally", "state = " + state + " expected finally"); 845 846var state = ""; 847try { 848 ok(state === "", "try: state = " + state); 849 state = "try"; 850 try { throw true; } finally {} 851}catch(ex) { 852 ok(state === "try", "catch: state = " + state); 853 ok(ex === true, "ex is not true"); 854 state = "catch"; 855}finally { 856 ok(state === "catch", "finally: state = " + state); 857 state = "finally"; 858} 859ok(state === "finally", "state = " + state + " expected finally"); 860 861var state = ""; 862try { 863 ok(state === "", "try: state = " + state); 864 state = "try"; 865 try { throw "except"; } catch(ex) { throw true; } 866}catch(ex) { 867 ok(state === "try", "catch: state = " + state); 868 ok(ex === true, "ex is not true"); 869 state = "catch"; 870}finally { 871 ok(state === "catch", "finally: state = " + state); 872 state = "finally"; 873} 874ok(state === "finally", "state = " + state + " expected finally"); 875 876function throwFunc(x) { 877 throw x; 878} 879 880var state = ""; 881try { 882 ok(state === "", "try: state = " + state); 883 state = "try"; 884 throwFunc(true); 885}catch(ex) { 886 ok(state === "try", "catch: state = " + state); 887 ok(ex === true, "ex is not true"); 888 state = "catch"; 889}finally { 890 ok(state === "catch", "finally: state = " + state); 891 state = "finally"; 892} 893ok(state === "finally", "state = " + state + " expected finally"); 894 895state = ""; 896switch(1) { 897case "1": 898 ok(false, "unexpected case \"1\""); 899case 1: 900 ok(state === "", "case 1: state = " + state); 901 state = "1"; 902default: 903 ok(state === "1", "default: state = " + state); 904 state = "default"; 905case false: 906 ok(state === "default", "case false: state = " + state); 907 state = "false"; 908} 909ok(state === "false", "state = " + state); 910 911state = ""; 912switch("") { 913case "1": 914case 1: 915 ok(false, "unexpected case 1"); 916default: 917 ok(state === "", "default: state = " + state); 918 state = "default"; 919case false: 920 ok(state === "default", "case false: state = " + state); 921 state = "false"; 922} 923ok(state === "false", "state = " + state); 924 925state = ""; 926switch(1) { 927case "1": 928 ok(false, "unexpected case \"1\""); 929case 1: 930 ok(state === "", "case 1: state = " + state); 931 state = "1"; 932default: 933 ok(state === "1", "default: state = " + state); 934 state = "default"; 935 break; 936case false: 937 ok(false, "unexpected case false"); 938} 939ok(state === "default", "state = " + state); 940 941switch(1) { 942case 2: 943 ok(false, "unexpected case 2"); 944case 3: 945 ok(false, "unexpected case 3"); 946} 947 948switch(1) { 949case 2: 950 ok(false, "unexpected case 2"); 951 break; 952default: 953 /* empty default */ 954} 955 956switch(2) { 957default: 958 ok(false, "unexpected default"); 959 break; 960case 2: 961 /* empty case */ 962}; 963 964switch(2) { 965default: 966 ok(false, "unexpected default"); 967 break; 968case 1: 969case 2: 970case 3: 971 /* empty case */ 972}; 973 974(function() { 975 var i=0; 976 977 switch(1) { 978 case 1: 979 i++; 980 } 981 return i; 982})(); 983 984(function() { 985 var ret, x; 986 987 function unreachable() { 988 ok(false, "unreachable"); 989 } 990 991 function expect(value, expect_value) { 992 ok(value === expect_value, "got " + value + " expected " + expect_value); 993 } 994 995 ret = (function() { 996 try { 997 return "try"; 998 unreachable(); 999 }catch(e) { 1000 unreachable(); 1001 }finally { 1002 return "finally"; 1003 unreachable(); 1004 } 1005 unreachable(); 1006 })(); 1007 expect(ret, "finally"); 1008 1009 x = ""; 1010 ret = (function() { 1011 try { 1012 x += "try,"; 1013 return x; 1014 unreachable(); 1015 }catch(e) { 1016 unreachable(); 1017 }finally { 1018 x += "finally,"; 1019 } 1020 unreachable(); 1021 })(); 1022 expect(ret, "try,"); 1023 expect(x, "try,finally,"); 1024 1025 x = ""; 1026 ret = (function() { 1027 try { 1028 x += "try," 1029 throw 1; 1030 unreachable(); 1031 }catch(e) { 1032 x += "catch,"; 1033 return "catch"; 1034 unreachable(); 1035 }finally { 1036 x += "finally,"; 1037 return "finally"; 1038 unreachable(); 1039 } 1040 unreachable(); 1041 })(); 1042 expect(ret, "finally"); 1043 expect(x, "try,catch,finally,"); 1044 1045 x = ""; 1046 ret = (function() { 1047 try { 1048 x += "try," 1049 throw 1; 1050 unreachable(); 1051 }catch(e) { 1052 x += "catch,"; 1053 return "catch"; 1054 unreachable(); 1055 }finally { 1056 x += "finally,"; 1057 } 1058 unreachable(); 1059 })(); 1060 expect(ret, "catch"); 1061 expect(x, "try,catch,finally,"); 1062 1063 x = ""; 1064 ret = (function() { 1065 try { 1066 x += "try," 1067 try { 1068 x += "try2,"; 1069 return "try2"; 1070 }catch(e) { 1071 unreachable(); 1072 }finally { 1073 x += "finally2,"; 1074 } 1075 unreachable(); 1076 }catch(e) { 1077 unreachable(); 1078 }finally { 1079 x += "finally,"; 1080 } 1081 unreachable(); 1082 })(); 1083 expect(ret, "try2"); 1084 expect(x, "try,try2,finally2,finally,"); 1085 1086 x = ""; 1087 ret = (function() { 1088 while(true) { 1089 try { 1090 x += "try," 1091 try { 1092 x += "try2,"; 1093 break; 1094 }catch(e) { 1095 unreachable(); 1096 }finally { 1097 x += "finally2,"; 1098 } 1099 unreachable(); 1100 }catch(e) { 1101 unreachable(); 1102 }finally { 1103 x += "finally,"; 1104 } 1105 unreachable(); 1106 } 1107 x += "ret"; 1108 return "ret"; 1109 })(); 1110 expect(ret, "ret"); 1111 expect(x, "try,try2,finally2,finally,ret"); 1112 1113 x = ""; 1114 ret = (function() { 1115 while(true) { 1116 try { 1117 x += "try," 1118 try { 1119 x += "try2,"; 1120 continue; 1121 }catch(e) { 1122 unreachable(); 1123 }finally { 1124 x += "finally2,"; 1125 } 1126 unreachable(); 1127 }catch(e) { 1128 unreachable(); 1129 }finally { 1130 x += "finally,"; 1131 break; 1132 } 1133 unreachable(); 1134 } 1135 x += "ret"; 1136 return "ret"; 1137 })(); 1138 expect(ret, "ret"); 1139 expect(x, "try,try2,finally2,finally,ret"); 1140})(); 1141 1142tmp = eval("1"); 1143ok(tmp === 1, "eval(\"1\") !== 1"); 1144eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;"); 1145ok(tmp === 2, "tmp !== 2"); 1146 1147ok(eval(false) === false, "eval(false) !== false"); 1148ok(eval() === undefined, "eval() !== undefined"); 1149 1150tmp = eval("1", "2"); 1151ok(tmp === 1, "eval(\"1\", \"2\") !== 1"); 1152 1153var state = ""; 1154try { 1155 ok(state === "", "try: state = " + state); 1156 state = "try"; 1157 eval("throwFunc(true);"); 1158}catch(ex) { 1159 ok(state === "try", "catch: state = " + state); 1160 ok(ex === true, "ex is not true"); 1161 state = "catch"; 1162}finally { 1163 ok(state === "catch", "finally: state = " + state); 1164 state = "finally"; 1165} 1166ok(state === "finally", "state = " + state + " expected finally"); 1167 1168tmp = [,,1,2,,,true]; 1169ok(tmp.length === 7, "tmp.length !== 7"); 1170ok(tmp["0"] === undefined, "tmp[0] is not undefined"); 1171ok(tmp["3"] === 2, "tmp[3] !== 2"); 1172ok(tmp["6"] === true, "tmp[6] !== true"); 1173ok(tmp[2] === 1, "tmp[2] !== 1"); 1174 1175ok([1,].length === 2, "[1,].length !== 2"); 1176ok([,,].length === 3, "[,,].length !== 3"); 1177ok([,].length === 2, "[].length != 2"); 1178ok([].length === 0, "[].length != 0"); 1179 1180tmp = 0; 1181while(tmp < 4) { 1182 ok(tmp < 4, "tmp >= 4"); 1183 tmp++; 1184} 1185ok(tmp === 4, "tmp !== 4"); 1186 1187tmp = 0; 1188while(true) { 1189 ok(tmp < 4, "tmp >= 4"); 1190 tmp++; 1191 if(tmp === 4) { 1192 break; 1193 ok(false, "break did not break"); 1194 } 1195} 1196ok(tmp === 4, "tmp !== 4"); 1197 1198tmp = 0; 1199do { 1200 ok(tmp < 4, "tmp >= 4"); 1201 tmp++; 1202} while(tmp < 4); 1203ok(tmp === 4, "tmp !== 4"); 1204 1205tmp = 0; 1206do { 1207 ok(tmp === 0, "tmp !=== 0"); 1208 tmp++; 1209} while(false); 1210ok(tmp === 1, "tmp !== 1"); 1211 1212tmp = 0; 1213do { 1214 ok(tmp < 4, "tmp >= 4"); 1215 tmp++; 1216} while(tmp < 4) 1217ok(tmp === 4, "tmp !== 4") 1218 1219tmp = 0; 1220while(tmp < 4) { 1221 tmp++; 1222 if(tmp === 2) { 1223 continue; 1224 ok(false, "break did not break"); 1225 } 1226 ok(tmp <= 4 && tmp != 2, "tmp = " + tmp); 1227} 1228ok(tmp === 4, "tmp !== 4"); 1229 1230for(tmp=0; tmp < 4; tmp++) 1231 ok(tmp < 4, "tmp = " + tmp); 1232ok(tmp === 4, "tmp !== 4"); 1233 1234for(tmp=0; tmp < 4; tmp++) { 1235 if(tmp === 2) 1236 break; 1237 ok(tmp < 2, "tmp = " + tmp); 1238} 1239ok(tmp === 2, "tmp !== 2"); 1240 1241for(tmp=0; tmp < 4; tmp++) { 1242 if(tmp === 2) 1243 continue; 1244 ok(tmp < 4 && tmp != 2, "tmp = " + tmp); 1245} 1246ok(tmp === 4, "tmp !== 4"); 1247 1248for(var fi=0; fi < 4; fi++) 1249 ok(fi < 4, "fi = " + fi); 1250ok(fi === 4, "fi !== 4"); 1251 1252tmp = true; 1253obj1 = new Object(); 1254for(obj1.nonexistent; tmp; tmp = false) 1255 ok(!("nonexistent" in obj1), "nonexistent added to obj1"); 1256 1257obj1 = new Object(); 1258for(tmp in obj1.nonexistent) 1259 ok(false, "for(tmp in obj1.nonexistent) called with tmp = " + tmp); 1260ok(!("nonexistent" in obj1), "nonexistent added to obj1 by for..in loop"); 1261 1262 1263var i, j; 1264 1265/* Previous versions have broken finally block implementation */ 1266if(ScriptEngineMinorVersion() >= 8) { 1267 tmp = ""; 1268 i = 0; 1269 while(true) { 1270 tmp += "1"; 1271 for(i = 1; i < 3; i++) { 1272 switch(i) { 1273 case 1: 1274 tmp += "2"; 1275 continue; 1276 case 2: 1277 tmp += "3"; 1278 try { 1279 throw null; 1280 }finally { 1281 tmp += "4"; 1282 break; 1283 } 1284 default: 1285 ok(false, "unexpected state"); 1286 } 1287 tmp += "5"; 1288 } 1289 with({prop: "6"}) { 1290 tmp += prop; 1291 break; 1292 } 1293 } 1294 ok(tmp === "123456", "tmp = " + tmp); 1295} 1296 1297tmp = ""; 1298i = 0; 1299for(j in [1,2,3]) { 1300 tmp += "1"; 1301 for(;;) { 1302 with({prop: "2"}) { 1303 tmp += prop; 1304 try { 1305 throw "3"; 1306 }catch(e) { 1307 tmp += e; 1308 with([0]) 1309 break; 1310 } 1311 } 1312 ok(false, "unexpected state"); 1313 } 1314 while(true) { 1315 tmp += "4"; 1316 break; 1317 } 1318 break; 1319} 1320ok(tmp === "1234", "tmp = " + tmp); 1321 1322tmp = 0; 1323for(var iter in [1,2,3]) { 1324 tmp += +iter; 1325 continue; 1326} 1327ok(tmp === 3, "tmp = " + tmp); 1328 1329tmp = false; 1330for(var iter in [1,2,3]) { 1331 switch(+iter) { 1332 case 1: 1333 tmp = true; 1334 try { 1335 continue; 1336 }finally {} 1337 default: 1338 continue; 1339 } 1340} 1341ok(tmp, "tmp = " + tmp); 1342 1343loop_label: 1344while(true) { 1345 while(true) 1346 break loop_label; 1347} 1348 1349loop_label: { 1350 tmp = 0; 1351 while(true) { 1352 while(true) 1353 break loop_label; 1354 } 1355 ok(false, "unexpected evaluation 1"); 1356} 1357 1358while(true) { 1359 some_label: break; 1360 ok(false, "unexpected evaluation 2"); 1361} 1362 1363just_label: tmp = 1; 1364ok(tmp === 1, "tmp != 1"); 1365 1366some_label: break some_label; 1367 1368other_label: { 1369 break other_label; 1370 ok(false, "unexpected evaluation 3"); 1371} 1372 1373loop_label: 1374do { 1375 while(true) 1376 continue loop_label; 1377}while(false); 1378 1379loop_label: 1380for(i = 0; i < 3; i++) { 1381 while(true) 1382 continue loop_label; 1383} 1384 1385loop_label: 1386other_label: 1387for(i = 0; i < 3; i++) { 1388 while(true) 1389 continue loop_label; 1390} 1391 1392loop_label: 1393for(tmp in {prop: false}) { 1394 while(true) 1395 continue loop_label; 1396} 1397 1398ok((void 1) === undefined, "(void 1) !== undefined"); 1399 1400var inobj = new Object(); 1401 1402for(var iter in inobj) 1403 ok(false, "unexpected iter = " + iter); 1404 1405inobj.test = true; 1406tmp = 0; 1407for(iter in inobj) { 1408 ok(iter == "test", "unexpected iter = " + iter); 1409 tmp++; 1410} 1411ok(tmp === 1, "for..in tmp = " + tmp); 1412 1413function forinTestObj() {} 1414 1415forinTestObj.prototype.test3 = true; 1416 1417var arr = new Array(); 1418inobj = new forinTestObj(); 1419inobj.test1 = true; 1420inobj.test2 = true; 1421 1422tmp = 0; 1423for(iter in inobj) { 1424 arr[iter] = true; 1425 tmp++; 1426} 1427 1428ok(tmp === 3, "for..in tmp = " + tmp); 1429ok(arr["test1"] === true, "arr[test1] !== true"); 1430ok(arr["test2"] === true, "arr[test2] !== true"); 1431ok(arr["test3"] === true, "arr[test3] !== true"); 1432 1433tmp = new Object(); 1434tmp.test = false; 1435ok((delete tmp.test) === true, "delete returned false"); 1436ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test)); 1437ok(!("test" in tmp), "test is still in tmp after delete?"); 1438for(iter in tmp) 1439 ok(false, "tmp has prop " + iter); 1440ok((delete tmp.test) === true, "deleting test didn't return true"); 1441ok((delete tmp.nonexistent) === true, "deleting nonexistent didn't return true"); 1442ok((delete nonexistent) === true, "deleting nonexistent didn't return true"); 1443 1444tmp = new Object(); 1445tmp.test = false; 1446ok((delete tmp["test"]) === true, "delete returned false"); 1447ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test)); 1448ok(!("test" in tmp), "test is still in tmp after delete?"); 1449 1450tmp.testWith = true; 1451with(tmp) 1452 ok(testWith === true, "testWith !== true"); 1453 1454if(false) { 1455 var varTest1 = true; 1456} 1457 1458ok(varTest1 === undefined, "varTest1 = " + varTest1); 1459ok(varTest2 === undefined, "varTest2 = " + varTest1); 1460 1461var varTest2; 1462 1463function varTestFunc(varTest3) { 1464 var varTest3; 1465 1466 ok(varTest3 === 3, "varTest3 = " + varTest3); 1467 ok(varTest4 === undefined, "varTest4 = " + varTest4); 1468 1469 var varTest4; 1470} 1471 1472varTestFunc(3); 1473 1474deleteTest = 1; 1475delete deleteTest; 1476try { 1477 tmp = deleteTest; 1478 ok(false, "deleteTest not throwed exception?"); 1479}catch(ex) {} 1480 1481(function() { 1482 var to_delete = 2; 1483 var r = delete to_delete; 1484 ok(r === false, "delete 1 returned " + r); 1485 if(r) 1486 return; 1487 ok(to_delete === 2, "to_delete = " + to_delete); 1488 1489 to_delete = new Object(); 1490 r = delete to_delete; 1491 ok(r === false, "delete 2 returned " + r); 1492 ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete)); 1493})(); 1494 1495(function(to_delete) { 1496 var r = delete to_delete; 1497 ok(r === false, "delete 3 returned " + r); 1498 ok(to_delete === 2, "to_delete = " + to_delete); 1499 1500 to_delete = new Object(); 1501 r = delete to_delete; 1502 ok(r === false, "delete 4 returned " + r); 1503 ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete)); 1504})(2); 1505 1506(function() { 1507 with({to_delete: new Object()}) { 1508 var r = delete to_delete; 1509 ok(r === true, "delete returned " + r); 1510 } 1511})(); 1512 1513if (false) 1514 if (true) 1515 ok(false, "if evaluated"); 1516 else 1517 ok(false, "else should be associated with nearest if statement"); 1518 1519if (true) 1520 if (false) 1521 ok(false, "if evaluated"); 1522 else 1523 ok(true, "else should be associated with nearest if statement"); 1524 1525function instanceOfTest() {} 1526tmp = new instanceOfTest(); 1527 1528ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest"); 1529ok((tmp instanceof Object) === true, "tmp is not instance of Object"); 1530ok((tmp instanceof String) === false, "tmp is instance of String"); 1531 1532instanceOfTest.prototype = new Object(); 1533ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest"); 1534ok((tmp instanceof Object) === true, "tmp is not instance of Object"); 1535 1536ok((1 instanceof Object) === false, "1 is instance of Object"); 1537ok((false instanceof Boolean) === false, "false is instance of Boolean"); 1538ok(("" instanceof Object) === false, "'' is instance of Object"); 1539 1540(function () { 1541 ok((arguments instanceof Object) === true, "argument is not instance of Object"); 1542 ok((arguments instanceof Array) === false, "argument is not instance of Array"); 1543 ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString()); 1544})(1,2); 1545 1546obj = new String(); 1547ok(("length" in obj) === true, "length is not in obj"); 1548ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj"); 1549ok(("abc" in obj) === false, "test is in obj"); 1550obj.abc = 1; 1551ok(("abc" in obj) === true, "test is not in obj"); 1552ok(("1" in obj) === false, "1 is in obj"); 1553 1554obj = [1,2,3]; 1555ok((1 in obj) === true, "1 is not in obj"); 1556 1557obj = new Object(); 1558try { 1559 obj.prop["test"]; 1560 ok(false, "expected exception"); 1561}catch(e) {} 1562ok(!("prop" in obj), "prop in obj"); 1563 1564if(invokeVersion >= 2) { 1565 ok("test"[0] === "t", '"test"[0] = ' + test[0]); 1566 ok("test"[5] === undefined, '"test"[0] = ' + test[0]); 1567 1568 tmp = "test"; 1569 ok(tmp[1] === "e", "tmp[1] = " + tmp[1]); 1570 tmp[1] = "x"; 1571 ok(tmp[1] === "e", "tmp[1] = " + tmp[1]); 1572 ok(tmp["1"] === "e", "tmp['1'] = " + tmp["1"]); 1573 ok(tmp["0x1"] === undefined, "tmp['0x1'] = " + tmp["0x1"]); 1574}else { 1575 ok("test"[0] === undefined, '"test"[0] = ' + test[0]); 1576} 1577 1578ok(isNaN(NaN) === true, "isNaN(NaN) !== true"); 1579ok(isNaN(0.5) === false, "isNaN(0.5) !== false"); 1580ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false"); 1581ok(isNaN() === true, "isNaN() !== true"); 1582ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true"); 1583ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false"); 1584ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true"); 1585 1586ok(isFinite(0.5) === true, "isFinite(0.5) !== true"); 1587ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false"); 1588ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false"); 1589ok(isFinite(NaN) === false, "isFinite(NaN) !== false"); 1590ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true"); 1591ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false"); 1592ok(isFinite() === false, "isFinite() !== false"); 1593 1594ok((1 < NaN) === false, "(1 < NaN) !== false"); 1595ok((1 > NaN) === false, "(1 > NaN) !== false"); 1596ok((1 <= NaN) === false, "(1 <= NaN) !== false"); 1597ok((1 >= NaN) === false, "(1 >= NaN) !== false"); 1598ok((NaN < 1) === false, "(NaN < 1) !== false"); 1599ok((NaN > 1) === false, "(NaN > 1) !== false"); 1600ok((NaN <= 1) === false, "(NaN <= 1) !== false"); 1601ok((NaN >= 1) === false, "(NaN >= 1) !== false"); 1602ok((Infinity < 2) === false, "(Infinity < 2) !== false"); 1603ok((Infinity > 2) === true, "(Infinity > 2) !== true"); 1604ok((-Infinity < 2) === true, "(-Infinity < 2) !== true"); 1605 1606ok(isNaN(+"test") === true, "isNaN(+'test') !== true"); 1607ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true"); 1608ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true"); 1609ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity"); 1610ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity"); 1611ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity"); 1612 1613ok((NaN !== NaN) === true, "(NaN !== NaN) !== true"); 1614ok((NaN === NaN) === false, "(NaN === NaN) !== false"); 1615ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true"); 1616ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true"); 1617ok((0 === NaN) === false, "(0 === NaN) !== false"); 1618 1619ok((NaN != NaN) === true, "(NaN !== NaN) != true"); 1620ok((NaN == NaN) === false, "(NaN === NaN) != false"); 1621ok((Infinity != NaN) === true, "(Infinity != NaN) !== true"); 1622ok((Infinity != NaN) === true, "(Infinity != NaN) !== true"); 1623ok((0 == NaN) === false, "(0 === NaN) != false"); 1624 1625// escape tests 1626var escapeTests = [ 1627 ["\'", "\\'", 39], 1628 ["\"", "\\\"", 34], 1629 ["\\", "\\\\", 92], 1630 ["\b", "\\b", 8], 1631 ["\t", "\\t", 9], 1632 ["\n", "\\n", 10], 1633 ["\v", "\\v", 118], 1634 ["\f", "\\f", 12], 1635 ["\r", "\\r", 13], 1636 ["\xf3", "\\xf3", 0xf3], 1637 ["\u1234", "\\u1234", 0x1234], 1638 ["\a", "\\a", 97], 1639 ["\?", "\\?", 63] 1640]; 1641 1642for(i=0; i<escapeTests.length; i++) { 1643 tmp = escapeTests[i][0].charCodeAt(0); 1644 ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]); 1645} 1646 1647tmp = !+"\v1"; 1648ok(tmp === true, '!+"\v1" = ' + tmp); 1649 1650ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2)); 1651tmp = testFunc2(1); 1652ok(tmp === 2, "testFunc2(1) = " + tmp); 1653function testFunc2(x) { return x+1; } 1654 1655ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3)); 1656tmp = testFunc3(1); 1657ok(tmp === 3, "testFunc3(1) = " + tmp); 1658tmp = function testFunc3(x) { return x+2; }; 1659 1660tmp = testFunc4(1); 1661ok(tmp === 5, "testFunc4(1) = " + tmp); 1662tmp = function testFunc4(x) { return x+3; }; 1663tmp = testFunc4(1); 1664testFunc4 = 1; 1665ok(testFunc4 === 1, "testFunc4 = " + testFunc4); 1666ok(tmp === 5, "testFunc4(1) = " + tmp); 1667tmp = function testFunc4(x) { return x+4; }; 1668ok(testFunc4 === 1, "testFunc4 = " + testFunc4); 1669 1670function testEmbeddedFunctions() { 1671 ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5)); 1672 tmp = testFunc5(1); 1673 ok(tmp === 3, "testFunc5(1) = " + tmp); 1674 tmp = function testFunc5(x) { return x+2; }; 1675 1676 tmp = testFunc6(1); 1677 ok(tmp === 5, "testFunc6(1) = " + tmp); 1678 tmp = function testFunc6(x) { return x+3; }; 1679 tmp = testFunc6(1); 1680 ok(tmp === 5, "testFunc6(1) = " + tmp); 1681 tmp = function testFunc6(x) { return x+4; }; 1682 testFunc6 = 1; 1683 ok(testFunc6 === 1, "testFunc4 = " + testFunc6); 1684} 1685 1686testEmbeddedFunctions(); 1687 1688date = new Date(); 1689date.toString = function() { return "toString"; } 1690ok(""+date === "toString", "''+date = " + date); 1691date.toString = function() { return this; } 1692ok(""+date === ""+date.valueOf(), "''+date = " + date); 1693 1694str = new String("test"); 1695str.valueOf = function() { return "valueOf"; } 1696ok(""+str === "valueOf", "''+str = " + str); 1697str.valueOf = function() { return new Date(); } 1698ok(""+str === "test", "''+str = " + str); 1699 1700ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})()); 1701 1702var re = /=(\?|%3F)/g; 1703ok(re.source === "=(\\?|%3F)", "re.source = " + re.source); 1704 1705tmp = new Array(); 1706for(var i=0; i<2; i++) 1707 tmp[i] = /b/; 1708ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]"); 1709 1710ok(isNullBSTR(getNullBSTR()), "isNullBSTR(getNullBSTR()) failed\n"); 1711ok(getNullBSTR() === '', "getNullBSTR() !== ''"); 1712ok(+getNullBSTR() === 0 , "+getNullBTR() !=== 0"); 1713 1714ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp)); 1715ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp)); 1716ok(nullDisp === nullDisp, "nullDisp !== nullDisp"); 1717ok(nullDisp !== re, "nullDisp === re"); 1718ok(nullDisp === null, "nullDisp === null"); 1719ok(nullDisp == null, "nullDisp == null"); 1720ok(getVT(true && nullDisp) === "VT_DISPATCH", 1721 "getVT(0 && nullDisp) = " + getVT(true && nullDisp)); 1722ok(!nullDisp === true, "!nullDisp = " + !nullDisp); 1723ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp)); 1724ok(nullDisp != new Object(), "nullDisp == new Object()"); 1725ok(new Object() != nullDisp, "new Object() == nullDisp"); 1726ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'"); 1727tmp = getVT(Object(nullDisp)); 1728ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp); 1729tmp = Object(nullDisp).toString(); 1730ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp); 1731 1732function do_test() {} 1733function nosemicolon() {} nosemicolon(); 1734function () {} nosemicolon(); 1735 1736if(false) { 1737 function in_if_false() { return true; } ok(false, "!?"); 1738} 1739 1740ok(in_if_false(), "in_if_false failed"); 1741 1742(function() { newValue = 1; })(); 1743ok(newValue === 1, "newValue = " + newValue); 1744 1745obj = {undefined: 3}; 1746 1747ok(typeof(name_override_func) === "function", "typeof(name_override_func) = " + typeof(name_override_func)); 1748name_override_func = 3; 1749ok(name_override_func === 3, "name_override_func = " + name_override_func); 1750function name_override_func() {}; 1751ok(name_override_func === 3, "name_override_func = " + name_override_func); 1752 1753tmp = (function() { 1754 var ret = false; 1755 with({ret: true}) 1756 return ret; 1757})(); 1758ok(tmp, "tmp = " + tmp); 1759 1760tmp = (function() { 1761 for(var iter in [1,2,3,4]) { 1762 var ret = false; 1763 with({ret: true}) 1764 return ret; 1765 } 1766})(); 1767ok(tmp, "tmp = " + tmp); 1768 1769(function() { 1770 ok(typeof(func) === "function", "typeof(func) = " + typeof(func)); 1771 with(new Object()) { 1772 var x = false && function func() {}; 1773 } 1774 ok(typeof(func) === "function", "typeof(func) = " + typeof(func)); 1775})(); 1776 1777(function() { 1778 ok(x === undefined, "x = " + x); // x is declared, but never initialized 1779 with({x: 1}) { 1780 ok(x === 1, "x = " + x); 1781 var x = 2; 1782 ok(x === 2, "x = " + x); 1783 } 1784 ok(x === undefined, "x = " + x); 1785})(); 1786 1787/* NoNewline rule parser tests */ 1788while(true) { 1789 if(true) break 1790 tmp = false 1791} 1792 1793while(true) { 1794 if(true) break /* 1795 * no semicolon, but comment present */ 1796 tmp = false 1797} 1798 1799while(true) { 1800 if(true) break // no semicolon, but comment present 1801 tmp = false 1802} 1803 1804while(true) { 1805 break 1806 continue 1807 tmp = false 1808} 1809 1810function returnTest() { 1811 return 1812 true; 1813} 1814 1815ok(returnTest() === undefined, "returnTest = " + returnTest()); 1816 1817ActiveXObject = 1; 1818ok(ActiveXObject === 1, "ActiveXObject = " + ActiveXObject); 1819 1820Boolean = 1; 1821ok(Boolean === 1, "Boolean = " + Boolean); 1822 1823Object = 1; 1824ok(Object === 1, "Object = " + Object); 1825 1826Array = 1; 1827ok(Array === 1, "Array = " + Array); 1828 1829Date = 1; 1830ok(Date === 1, "Date = " + Date); 1831 1832Error = 1; 1833ok(Error === 1, "Error = " + Error); 1834 1835/* Keep this test in the end of file */ 1836undefined = 6; 1837ok(undefined === 6, "undefined = " + undefined); 1838 1839NaN = 6; 1840ok(NaN === 6, "NaN !== 6"); 1841 1842Infinity = 6; 1843ok(Infinity === 6, "Infinity !== 6"); 1844 1845Math = 6; 1846ok(Math === 6, "NaN !== 6"); 1847 1848reportSuccess(); 1849