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