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