2 * Copyright 2008 Jacek Caban for CodeWeavers
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.
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.
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
21 ok(true, "true is not true?");
22 ok(!false, "!false is not true");
23 ok(!undefined, "!undefined is not true");
24 ok(!null, "!null is not true");
25 ok(!0, "!0 is not true");
26 ok(!0.0, "!0.0 is not true");
28 ok(1 === 1, "1 === 1 is false");
29 ok(!(1 === 2), "!(1 === 2) is false");
30 ok(1.0 === 1, "1.0 === 1 is false");
31 ok("abc" === "abc", "\"abc\" === \"abc\" is false");
32 ok(true === true, "true === true is false");
33 ok(null === null, "null === null is false");
34 ok(undefined === undefined, "undefined === undefined is false");
35 ok(!(undefined === null), "!(undefined === null) is false");
36 ok(1E0 === 1, "1E0 === 1 is false");
37 ok(1000000*1000000 === 1000000000000, "1000000*1000000 === 1000000000000 is false");
38 ok(8.64e15 === 8640000000000000, "8.64e15 !== 8640000000000000");
39 ok(1e2147483648 === Infinity, "1e2147483648 !== Infinity");
41 ok(1 !== 2, "1 !== 2 is false");
42 ok(null !== undefined, "null !== undefined is false");
44 ok(1 == 1, "1 == 1 is false");
45 ok(!(1 == 2), "!(1 == 2) is false");
46 ok(1.0 == 1, "1.0 == 1 is false");
47 ok("abc" == "abc", "\"abc\" == \"abc\" is false");
48 ok(true == true, "true == true is false");
49 ok(null == null, "null == null is false");
50 ok(undefined == undefined, "undefined == undefined is false");
51 ok(undefined == null, "undefined == null is false");
52 ok(true == 1, "true == 1 is false");
53 ok(!(true == 2), "true == 2");
54 ok(0 == false, "0 == false is false");
56 ok(1 != 2, "1 != 2 is false");
57 ok(false != 1, "false != 1 is false");
60 ok(trueVar, "trueVar is not true");
62 ok(ScriptEngine.length === 0, "ScriptEngine.length is not 0");
64 function testFunc1(x, y) {
65 ok(this !== undefined, "this is undefined");
66 ok(x === true, "x is not true");
67 ok(y === "test", "y is not \"test\"");
68 ok(arguments.length === 2, "arguments.length is not 2");
69 ok(arguments["0"] === true, "arguments[0] is not true");
70 ok(arguments["1"] === "test", "arguments[1] is not \"test\"");
71 ok(arguments.callee === testFunc1, "arguments.calee !== testFunc1");
72 ok(testFunc1.arguments === arguments, "testFunc1.arguments = " + testFunc1.arguments);
77 ok(testFunc1.length === 2, "testFunc1.length is not 2");
78 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
80 ok(Object.prototype !== undefined, "Object.prototype is undefined");
81 ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
82 ok(String.prototype !== undefined, "String.prototype is undefined");
83 ok(Array.prototype !== undefined, "Array.prototype is undefined");
84 ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
85 ok(Number.prototype !== undefined, "Number.prototype is undefined");
86 ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
87 ok(Math !== undefined, "Math is undefined");
88 ok(Math.prototype === undefined, "Math.prototype is not undefined");
89 ok(Function.prototype !== undefined, "Function.prototype is undefined");
90 ok(Function.prototype.prototype === undefined, "Function.prototype.prototype is not undefined");
91 ok(Date.prototype !== undefined, "Date.prototype is undefined");
92 ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
94 Function.prototype.test = true;
95 ok(testFunc1.test === true, "testFunc1.test !== true");
96 ok(Function.test === true, "Function.test !== true");
98 ok(typeof(0) === "number", "typeof(0) is not number");
99 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
100 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
101 ok(typeof("") === "string", "typeof(\"\") is not string");
102 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
103 ok(typeof(null) === "object", "typeof(null) is not object");
104 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
105 ok(typeof(Math) === "object", "typeof(Math) is not object");
106 ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
107 ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
108 ok(typeof(String) === "function", "typeof(String) is not function");
109 ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
110 ok(typeof(this) === "object", "typeof(this) is not object");
111 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
112 tmp = typeof((new Object()).doesnotexist);
113 ok(tmp === "undefined", "typeof((new Object).doesnotexist = " + tmp);
114 tmp = typeof(testObj.onlyDispID);
115 ok(tmp === "unknown", "typeof(testObj.onlyDispID) = " + tmp);
117 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
119 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
122 ok(tmp === 3, "tmp = " + tmp);
124 function testRecFunc(x) {
125 ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
128 ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
129 ok(testRecFunc.arguments[0] === true, "testRecFunc.arguments.x = " + testRecFunc.arguments[0]);
133 testRecFunc.arguments = 5;
134 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
136 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
138 tmp = (function() {1;})();
139 ok(tmp === undefined, "tmp = " + tmp);
141 ok(tmp === 1, "tmp = " + tmp);
143 ok(tmp === 2, "tmp = " + tmp);
144 tmp = eval("if(true) {3}");
145 ok(tmp === 3, "tmp = " + tmp);
147 var obj1 = new Object();
148 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
149 ok(obj1.constructor === Object, "unexpected obj1.constructor");
151 obj1.func = function () {
152 ok(this === obj1, "this is not obj1");
153 ok(this.test === true, "this.test is not true");
154 ok(arguments.length === 1, "arguments.length is not 1");
155 ok(arguments["0"] === true, "arguments[0] is not true");
156 ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
161 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
163 function testConstr1() {
166 ok(this !== undefined, "this is undefined");
167 ok(arguments.length === 1, "arguments.length is not 1");
168 ok(arguments["0"] === true, "arguments[0] is not 1");
169 ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
174 testConstr1.prototype.pvar = 1;
176 var obj2 = new testConstr1(true);
177 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
178 ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
179 ok(obj2.pvar === 1, "obj2.pvar is not 1");
181 testConstr1.prototype.pvar = 2;
182 ok(obj2.pvar === 2, "obj2.pvar is not 2");
185 testConstr1.prototype.pvar = 1;
186 ok(obj2.pvar === 3, "obj2.pvar is not 3");
189 function testConstr3() {
193 obj2 = new testConstr3();
194 ok(obj1 === obj2, "obj1 != obj2");
196 function testConstr4() {
200 obj2 = new testConstr3();
201 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
203 var obj3 = new Object;
204 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
206 for(var iter in "test")
207 ok(false, "unexpected forin call, test = " + iter);
209 for(var iter in null)
210 ok(false, "unexpected forin call, test = " + iter);
212 for(var iter in false)
213 ok(false, "unexpected forin call, test = " + iter);
215 for(var iter in pureDisp)
216 ok(false, "unexpected forin call in pureDisp object");
219 ok(!tmp.nonexistent, "!tmp.nonexistent = " + !tmp.nonexistent);
220 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '!' expression")
223 ok((~tmp.nonexistent) === -1, "!tmp.nonexistent = " + ~tmp.nonexistent);
224 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '~' expression")
227 ok(isNaN(+tmp.nonexistent), "!tmp.nonexistent = " + (+tmp.nonexistent));
228 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '+' expression")
231 tmp[tmp.nonexistent];
232 ok(!("nonexistent" in tmp), "nonexistent is in tmp after array expression")
238 ok(false, "else evaluated");
239 ok(tmp === 1, "tmp !== 1, if not evaluated?");
243 ok(false, "if evaluated");
246 ok(tmp === 1, "tmp !== 1, if not evaluated?");
249 ok(false, "if(false) evaluated");
254 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
260 var obj3 = { prop1: 1, prop2: typeof(false) };
261 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
262 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
263 ok(obj3.constructor === Object, "unexpected obj3.constructor");
269 ok(blockVar === 2, "blockVar !== 2");
271 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
272 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
274 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
275 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
276 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
277 ok(getVT(0.5) === "VT_R8", "getVT(0.5) is not VT_R8");
278 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
279 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
280 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
283 ok(tmp === 4, "2+2 !== 4");
284 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
287 ok(tmp === 4.5, "2+2.5 !== 4.5");
288 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
291 ok(tmp === 4, "1.4+2.5 !== 4");
292 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
295 ok(tmp === 2, "4-2 !== 2");
296 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
299 ok(tmp === 2.5, "4.5-2 !== 2.5");
300 ok(getVT(tmp) === "VT_R8", "getVT(4.5-2) !== VT_R8");
303 ok(tmp === 0-2, "-2 !== 0-2");
304 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
307 ok(tmp === 6, "2*3 !== 6");
308 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
311 ok(tmp === 7, "2*3.5 !== 7");
312 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
315 /* FIXME: the parser loses precision */
316 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
317 ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
318 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
321 ok(tmp === 2, "4/2 !== 2");
322 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
325 ok(tmp === 3, "4.5/1.5 !== 3");
326 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
329 ok(tmp === 1.5, "3/2 !== 1.5");
330 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
333 ok(tmp === 1, "3%2 = " + tmp);
336 ok(tmp ===0, "4%2 = " + tmp);
339 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
342 ok(tmp === 0, "3%true = " + tmp);
345 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
348 ok((tmp += 1) === 2, "tmp += 1 !== 2");
349 ok(tmp === 2, "tmp !== 2");
352 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
353 ok(tmp === 1, "tmp !=== 1");
356 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
357 ok(tmp === 3, "tmp !=== 3");
360 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
361 ok(tmp === 2.5, "tmp !=== 2.5");
364 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
365 ok(tmp === 1, "tmp !== 1");
368 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
371 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
374 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
376 tmp = 3 || ok(false, "second or expression called");
377 ok(tmp === 3, "3 || (...) is not 3");
380 ok(tmp === 2, "false || 2 is not 2");
382 tmp = 0 && ok(false, "second and expression called");
383 ok(tmp === 0, "0 && (...) is not 0");
385 tmp = true && "test";
386 ok(tmp === "test", "true && \"test\" is not \"test\"");
389 ok(tmp === 0, "true && 0 is not 0");
392 ok(tmp === 7, "3 | 4 !== 7");
393 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
396 ok(tmp === 3, "3.5 | 0 !== 3");
397 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
400 ok(tmp === -3, "-3.5 | 0 !== -3");
401 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
404 ok(tmp === 0, "0 | NaN = " + tmp);
407 ok(tmp === 0, "0 | NaN = " + tmp);
409 tmp = 0 | (-Infinity);
410 ok(tmp === 0, "0 | NaN = " + tmp);
413 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
414 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
417 ok(tmp === 1, "3 & 5 !== 1");
418 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
421 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
422 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
424 tmp = (-3.5) & 0xffffffff;
425 ok(tmp === -3, "-3.5 & 0xffff !== -3");
426 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
429 ok(tmp === 16, "2 << 3 = " + tmp);
432 ok(tmp === 16, "2 << 35 = " + tmp);
435 ok(tmp === 2, "8 >> 2 = " + tmp);
438 ok(tmp === -4, "-64 >> 4 = " + tmp);
441 ok(tmp === 2, "8 >> 2 = " + tmp);
444 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
447 ok(tmp === 4, "4 >>> NaN = " + tmp);
450 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
451 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
454 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
455 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
458 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
459 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
462 ok(tmp === -2, "~1 !== -2");
463 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
465 ok((3,4) === 4, "(3,4) !== 4");
467 ok(+3 === 3, "+3 !== 3");
468 ok(+true === 1, "+true !== 1");
469 ok(+false === 0, "+false !== 0");
470 ok(+null === 0, "+null !== 0");
471 ok(+"0" === 0, "+'0' !== 0");
472 ok(+"3" === 3, "+'3' !== 3");
473 ok(+"-3" === -3, "+'-3' !== -3");
474 ok(+"0xff" === 255, "+'0xff' !== 255");
475 ok(+"3e3" === 3000, "+'3e3' !== 3000");
478 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
479 ok(tmp.constructor === Number, "unexpected tmp.constructor");
480 tmp = new String("1");
481 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
482 ok(tmp.constructor === String, "unexpected tmp.constructor");
484 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
485 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
486 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
487 ok("" + null === "null", "\"\" + null !== \"null\"");
488 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
489 ok("" + true === "true", "\"\" + true !== \"true\"");
490 ok("" + false === "false", "\"\" + false !== \"false\"");
491 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
492 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
494 ok(1 < 3.4, "1 < 3.4 failed");
495 ok(!(3.4 < 1), "3.4 < 1");
496 ok("abc" < "abcd", "abc < abcd failed");
497 ok("abcd" < "abce", "abce < abce failed");
498 ok("" < "x", "\"\" < \"x\" failed");
499 ok(!(0 < 0), "0 < 0");
501 ok(1 <= 3.4, "1 <= 3.4 failed");
502 ok(!(3.4 <= 1), "3.4 <= 1");
503 ok("abc" <= "abcd", "abc <= abcd failed");
504 ok("abcd" <= "abce", "abce <= abce failed");
505 ok("" <= "x", "\"\" <= \"x\" failed");
506 ok(0 <= 0, "0 <= 0 failed");
508 ok(3.4 > 1, "3.4 > 1 failed");
509 ok(!(1 > 3.4), "1 > 3.4");
510 ok("abcd" > "abc", "abc > abcd failed");
511 ok("abce" > "abcd", "abce > abce failed");
512 ok("x" > "", "\"x\" > \"\" failed");
513 ok(!(0 > 0), "0 > 0");
515 ok(3.4 >= 1, "3.4 >= 1 failed");
516 ok(!(1 >= 3.4), "1 >= 3.4");
517 ok("abcd" >= "abc", "abc >= abcd failed");
518 ok("abce" >= "abcd", "abce >= abce failed");
519 ok("x" >= "", "\"x\" >= \"\" failed");
520 ok(0 >= 0, "0 >= 0");
523 ok(++tmp === 2, "++tmp (1) is not 2");
524 ok(tmp === 2, "incremented tmp is not 2");
525 ok(--tmp === 1, "--tmp (2) is not 1");
526 ok(tmp === 1, "decremented tmp is not 1");
527 ok(tmp++ === 1, "tmp++ (1) is not 1");
528 ok(tmp === 2, "incremented tmp(1) is not 2");
529 ok(tmp-- === 2, "tmp-- (2) is not 2");
530 ok(tmp === 1, "decremented tmp is not 1");
534 ok(isNaN(tmp.iii), "tmp.iii = " + tmp.iii);
536 String.prototype.test = true;
537 ok("".test === true, "\"\".test is not true");
539 Boolean.prototype.test = true;
540 ok(true.test === true, "true.test is not true");
542 Number.prototype.test = true;
543 ok((0).test === true, "(0).test is not true");
544 ok((0.5).test === true, "(0.5).test is not true");
548 ok(state === "", "try: state = " + state);
551 ok(false, "unexpected catch");
553 ok(state === "try", "state = " + state + " expected try");
557 ok(state === "", "try: state = " + state);
560 ok(state === "try", "finally: state = " + state);
563 ok(state === "finally", "state = " + state + " expected finally");
573 ok(state === "finally", "state = " + state + " expected finally");
576 ok(state === "catch", "state = " + state + " expected catch");
585 ok(e === 1, "e = " + e);
590 ok(state === "", "try: state = " + state);
593 ok(false, "unexpected catch");
595 ok(state === "try", "finally: state = " + state);
598 ok(state === "finally", "state = " + state + " expected finally");
602 ok(state === "", "try: state = " + state);
606 ok(state === "try", "catch: state = " + state);
607 ok(ex === "except", "ex is not \"except\"");
610 ok(state === "catch", "state = " + state + " expected catch");
614 ok(state === "", "try: state = " + state);
618 ok(state === "try", "catch: state = " + state);
619 ok(ex === true, "ex is not true");
622 ok(state === "catch", "finally: state = " + state);
625 ok(state === "finally", "state = " + state + " expected finally");
629 ok(state === "", "try: state = " + state);
631 try { throw true; } finally {}
633 ok(state === "try", "catch: state = " + state);
634 ok(ex === true, "ex is not true");
637 ok(state === "catch", "finally: state = " + state);
640 ok(state === "finally", "state = " + state + " expected finally");
644 ok(state === "", "try: state = " + state);
646 try { throw "except"; } catch(ex) { throw true; }
648 ok(state === "try", "catch: state = " + state);
649 ok(ex === true, "ex is not true");
652 ok(state === "catch", "finally: state = " + state);
655 ok(state === "finally", "state = " + state + " expected finally");
657 function throwFunc(x) {
663 ok(state === "", "try: state = " + state);
667 ok(state === "try", "catch: state = " + state);
668 ok(ex === true, "ex is not true");
671 ok(state === "catch", "finally: state = " + state);
674 ok(state === "finally", "state = " + state + " expected finally");
679 ok(false, "unexpected case \"1\"");
681 ok(state === "", "case 1: state = " + state);
684 ok(state === "1", "default: state = " + state);
687 ok(state === "default", "case false: state = " + state);
690 ok(state === "false", "state = " + state);
696 ok(false, "unexpected case 1");
698 ok(state === "", "default: state = " + state);
701 ok(state === "default", "case false: state = " + state);
704 ok(state === "false", "state = " + state);
709 ok(false, "unexpected case \"1\"");
711 ok(state === "", "case 1: state = " + state);
714 ok(state === "1", "default: state = " + state);
718 ok(false, "unexpected case false");
720 ok(state === "default", "state = " + state);
723 ok(tmp === 1, "eval(\"1\") !== 1");
724 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
725 ok(tmp === 2, "tmp !== 2");
727 ok(eval(false) === false, "eval(false) !== false");
728 ok(eval() === undefined, "eval() !== undefined");
730 tmp = eval("1", "2");
731 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
735 ok(state === "", "try: state = " + state);
737 eval("throwFunc(true);");
739 ok(state === "try", "catch: state = " + state);
740 ok(ex === true, "ex is not true");
743 ok(state === "catch", "finally: state = " + state);
746 ok(state === "finally", "state = " + state + " expected finally");
748 tmp = [,,1,2,,,true];
749 ok(tmp.length === 7, "tmp.length !== 7");
750 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
751 ok(tmp["3"] === 2, "tmp[3] !== 2");
752 ok(tmp["6"] === true, "tmp[6] !== true");
753 ok(tmp[2] === 1, "tmp[2] !== 1");
755 ok([1,].length === 2, "[1,].length !== 2");
756 ok([,,].length === 3, "[,,].length !== 3");
757 ok([,].length === 2, "[].length != 2");
758 ok([].length === 0, "[].length != 0");
762 ok(tmp < 4, "tmp >= 4");
765 ok(tmp === 4, "tmp !== 4");
769 ok(tmp < 4, "tmp >= 4");
773 ok(false, "break did not break");
776 ok(tmp === 4, "tmp !== 4");
780 ok(tmp < 4, "tmp >= 4");
783 ok(tmp === 4, "tmp !== 4");
787 ok(tmp === 0, "tmp !=== 0");
790 ok(tmp === 1, "tmp !== 1");
794 ok(tmp < 4, "tmp >= 4");
797 ok(tmp === 4, "tmp !== 4")
804 ok(false, "break did not break");
806 ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
808 ok(tmp === 4, "tmp !== 4");
810 for(tmp=0; tmp < 4; tmp++)
811 ok(tmp < 4, "tmp = " + tmp);
812 ok(tmp === 4, "tmp !== 4");
814 for(tmp=0; tmp < 4; tmp++) {
817 ok(tmp < 2, "tmp = " + tmp);
819 ok(tmp === 2, "tmp !== 2");
821 for(tmp=0; tmp < 4; tmp++) {
824 ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
826 ok(tmp === 4, "tmp !== 4");
828 for(var fi=0; fi < 4; fi++)
829 ok(fi < 4, "fi = " + fi);
830 ok(fi === 4, "fi !== 4");
834 for(obj1.nonexistent; tmp; tmp = false)
835 ok(!("nonexistent" in obj1), "nonexistent added to obj1");
838 for(tmp in obj1.nonexistent)
839 ok(false, "for(tmp in obj1.nonexistent) called with tmp = " + tmp);
840 ok(!("nonexistent" in obj1), "nonexistent added to obj1 by for..in loop");
845 /* Previous versions have broken finally block implementation */
846 if(ScriptEngineMinorVersion() >= 8) {
851 for(i = 1; i < 3; i++) {
865 ok(false, "unexpected state");
874 ok(tmp === "123456", "tmp = " + tmp);
892 ok(false, "unexpected state");
900 ok(tmp === "1234", "tmp = " + tmp);
903 for(var iter in [1,2,3]) {
907 ok(tmp === 3, "tmp = " + tmp);
910 for(var iter in [1,2,3]) {
921 ok(tmp, "tmp = " + tmp);
935 ok(false, "unexpected evaluation 1");
940 ok(false, "unexpected evaluation 2");
944 ok(tmp === 1, "tmp != 1");
946 some_label: break some_label;
950 ok(false, "unexpected evaluation 3");
960 for(i = 0; i < 3; i++) {
967 for(i = 0; i < 3; i++) {
973 for(tmp in {prop: false}) {
978 ok((void 1) === undefined, "(void 1) !== undefined");
980 var inobj = new Object();
982 for(var iter in inobj)
983 ok(false, "unexpected iter = " + iter);
988 ok(iter == "test", "unexpected iter = " + iter);
991 ok(tmp === 1, "for..in tmp = " + tmp);
993 function forinTestObj() {}
995 forinTestObj.prototype.test3 = true;
997 var arr = new Array();
998 inobj = new forinTestObj();
1003 for(iter in inobj) {
1008 ok(tmp === 3, "for..in tmp = " + tmp);
1009 ok(arr["test1"] === true, "arr[test1] !== true");
1010 ok(arr["test2"] === true, "arr[test2] !== true");
1011 ok(arr["test3"] === true, "arr[test3] !== true");
1015 ok((delete tmp.test) === true, "delete returned false");
1016 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1017 ok(!("test" in tmp), "test is still in tmp after delete?");
1019 ok(false, "tmp has prop " + iter);
1023 ok((delete tmp["test"]) === true, "delete returned false");
1024 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1025 ok(!("test" in tmp), "test is still in tmp after delete?");
1027 tmp.testWith = true;
1029 ok(testWith === true, "testWith !== true");
1032 var varTest1 = true;
1035 ok(varTest1 === undefined, "varTest1 = " + varTest1);
1036 ok(varTest2 === undefined, "varTest2 = " + varTest1);
1040 function varTestFunc(varTest3) {
1043 ok(varTest3 === 3, "varTest3 = " + varTest3);
1044 ok(varTest4 === undefined, "varTest4 = " + varTest4);
1055 ok(false, "deleteTest not throwed exception?");
1060 ok(false, "if evaluated");
1062 ok(false, "else should be associated with nearest if statement");
1066 ok(false, "if evaluated");
1068 ok(true, "else should be associated with nearest if statement");
1070 function instanceOfTest() {}
1071 tmp = new instanceOfTest();
1073 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
1074 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1075 ok((tmp instanceof String) === false, "tmp is instance of String");
1077 instanceOfTest.prototype = new Object();
1078 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
1079 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1081 ok((1 instanceof Object) === false, "1 is instance of Object");
1082 ok((false instanceof Boolean) === false, "false is instance of Boolean");
1083 ok(("" instanceof Object) === false, "'' is instance of Object");
1086 ok((arguments instanceof Object) === true, "argument is not instance of Object");
1087 ok((arguments instanceof Array) === false, "argument is not instance of Array");
1088 ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
1092 ok(("length" in obj) === true, "length is not in obj");
1093 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
1094 ok(("abc" in obj) === false, "test is in obj");
1096 ok(("abc" in obj) === true, "test is not in obj");
1097 ok(("1" in obj) === false, "1 is in obj");
1100 ok((1 in obj) === true, "1 is not in obj");
1105 ok(false, "expected exception");
1107 ok(!("prop" in obj), "prop in obj");
1109 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
1110 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
1111 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
1112 ok(isNaN() === true, "isNaN() !== true");
1113 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
1114 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
1115 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
1117 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
1118 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
1119 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
1120 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
1121 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
1122 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
1123 ok(isFinite() === false, "isFinite() !== false");
1125 ok((1 < NaN) === false, "(1 < NaN) !== false");
1126 ok((1 > NaN) === false, "(1 > NaN) !== false");
1127 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
1128 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
1129 ok((NaN < 1) === false, "(NaN < 1) !== false");
1130 ok((NaN > 1) === false, "(NaN > 1) !== false");
1131 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
1132 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
1133 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
1134 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
1135 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
1137 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
1138 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
1139 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
1140 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
1141 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
1142 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
1144 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
1145 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
1146 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1147 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1148 ok((0 === NaN) === false, "(0 === NaN) !== false");
1150 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
1151 ok((NaN == NaN) === false, "(NaN === NaN) != false");
1152 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1153 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1154 ok((0 == NaN) === false, "(0 === NaN) != false");
1167 ["\xf3", "\\xf3", 0xf3],
1168 ["\u1234", "\\u1234", 0x1234],
1173 for(i=0; i<escapeTests.length; i++) {
1174 tmp = escapeTests[i][0].charCodeAt(0);
1175 ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]);
1179 ok(tmp === true, '!+"\v1" = ' + tmp);
1181 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
1183 ok(tmp === 2, "testFunc2(1) = " + tmp);
1184 function testFunc2(x) { return x+1; }
1186 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
1188 ok(tmp === 3, "testFunc3(1) = " + tmp);
1189 tmp = function testFunc3(x) { return x+2; };
1192 ok(tmp === 5, "testFunc4(1) = " + tmp);
1193 tmp = function testFunc4(x) { return x+3; };
1196 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1197 ok(tmp === 5, "testFunc4(1) = " + tmp);
1198 tmp = function testFunc4(x) { return x+4; };
1199 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1201 function testEmbededFunctions() {
1202 ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
1204 ok(tmp === 3, "testFunc5(1) = " + tmp);
1205 tmp = function testFunc5(x) { return x+2; };
1208 ok(tmp === 5, "testFunc6(1) = " + tmp);
1209 tmp = function testFunc6(x) { return x+3; };
1211 ok(tmp === 5, "testFunc6(1) = " + tmp);
1212 tmp = function testFunc6(x) { return x+4; };
1214 ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
1217 testEmbededFunctions();
1220 date.toString = function() { return "toString"; }
1221 ok(""+date === "toString", "''+date = " + date);
1222 date.toString = function() { return this; }
1223 ok(""+date === ""+date.valueOf(), "''+date = " + date);
1225 str = new String("test");
1226 str.valueOf = function() { return "valueOf"; }
1227 ok(""+str === "valueOf", "''+str = " + str);
1228 str.valueOf = function() { return new Date(); }
1229 ok(""+str === "test", "''+str = " + str);
1231 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
1233 var re = /=(\?|%3F)/g;
1234 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
1237 for(var i=0; i<2; i++)
1239 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
1241 ok(isNullBSTR(getNullBSTR()), "isNullBSTR(getNullBSTR()) failed\n");
1242 ok(getNullBSTR() === '', "getNullBSTR() !== ''");
1243 ok(+getNullBSTR() === 0 , "+getNullBTR() !=== 0");
1245 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1246 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1247 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
1248 ok(nullDisp !== re, "nullDisp === re");
1249 ok(nullDisp === null, "nullDisp === null");
1250 ok(nullDisp == null, "nullDisp == null");
1251 ok(getVT(true && nullDisp) === "VT_DISPATCH",
1252 "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
1253 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1254 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1255 ok(nullDisp != new Object(), "nullDisp == new Object()");
1256 ok(new Object() != nullDisp, "new Object() == nullDisp");
1257 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1258 tmp = getVT(Object(nullDisp));
1259 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1260 tmp = Object(nullDisp).toString();
1261 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1263 function do_test() {}
1264 function nosemicolon() {} nosemicolon();
1265 function () {} nosemicolon();
1268 function in_if_false() { return true; } ok(false, "!?");
1271 ok(in_if_false(), "in_if_false failed");
1273 (function() { newValue = 1; })();
1274 ok(newValue === 1, "newValue = " + newValue);
1276 obj = {undefined: 3};
1278 ok(typeof(name_override_func) === "function", "typeof(name_override_func) = " + typeof(name_override_func));
1279 name_override_func = 3;
1280 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1281 function name_override_func() {};
1282 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1284 /* Keep this test in the end of file */
1286 ok(undefined === 6, "undefined = " + undefined);
1289 ok(NaN === 6, "NaN !== 6");
1292 ok(Infinity === 6, "Infinity !== 6");
1295 ok(Math === 6, "NaN !== 6");