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");
76 ok(testFunc1.length === 2, "testFunc1.length is not 2");
78 ok(Object.prototype !== undefined, "Object.prototype is undefined");
79 ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
80 ok(String.prototype !== undefined, "String.prototype is undefined");
81 ok(Array.prototype !== undefined, "Array.prototype is undefined");
82 ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
83 ok(Number.prototype !== undefined, "Number.prototype is undefined");
84 ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
85 ok(Math !== undefined, "Math is undefined");
86 ok(Math.prototype === undefined, "Math.prototype is not undefined");
87 ok(Function.prototype !== undefined, "Function.prototype is undefined");
88 ok(Function.prototype.prototype === undefined, "Function.prototype.prototype is not undefined");
89 ok(Date.prototype !== undefined, "Date.prototype is undefined");
90 ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
92 Function.prototype.test = true;
93 ok(testFunc1.test === true, "testFunc1.test !== true");
94 ok(Function.test === true, "Function.test !== true");
96 ok(typeof(0) === "number", "typeof(0) is not number");
97 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
98 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
99 ok(typeof("") === "string", "typeof(\"\") is not string");
100 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
101 ok(typeof(null) === "object", "typeof(null) is not object");
102 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
103 ok(typeof(Math) === "object", "typeof(Math) is not object");
104 ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
105 ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
106 ok(typeof(String) === "function", "typeof(String) is not function");
107 ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
108 ok(typeof(this) === "object", "typeof(this) is not object");
110 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
112 tmp = (function() {1;})();
113 ok(tmp === undefined, "tmp = " + tmp);
115 ok(tmp === 1, "tmp = " + tmp);
117 var obj1 = new Object();
118 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
119 ok(obj1.constructor === Object, "unexpected obj1.constructor");
121 obj1.func = function () {
122 ok(this === obj1, "this is not obj1");
123 ok(this.test === true, "this.test is not true");
124 ok(arguments.length === 1, "arguments.length is not 1");
125 ok(arguments["0"] === true, "arguments[0] is not true");
126 ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
131 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
133 function testConstr1() {
136 ok(this !== undefined, "this is undefined");
137 ok(arguments.length === 1, "arguments.length is not 1");
138 ok(arguments["0"] === true, "arguments[0] is not 1");
139 ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
144 testConstr1.prototype.pvar = 1;
146 var obj2 = new testConstr1(true);
147 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
148 ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
149 ok(obj2.pvar === 1, "obj2.pvar is not 1");
151 testConstr1.prototype.pvar = 2;
152 ok(obj2.pvar === 2, "obj2.pvar is not 2");
155 testConstr1.prototype.pvar = 1;
156 ok(obj2.pvar === 3, "obj2.pvar is not 3");
159 function testConstr3() {
163 obj2 = new testConstr3();
164 ok(obj1 === obj2, "obj1 != obj2");
166 function testConstr4() {
170 obj2 = new testConstr3();
171 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
173 var obj3 = new Object;
174 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
176 for(var iter in "test")
177 ok(false, "unexpected forin call, test = " + iter);
179 for(var iter in null)
180 ok(false, "unexpected forin call, test = " + iter);
182 for(var iter in false)
183 ok(false, "unexpected forin call, test = " + iter);
189 ok(false, "else evaluated");
190 ok(tmp === 1, "tmp !== 1, if not evaluated?");
194 ok(false, "if evaluated");
197 ok(tmp === 1, "tmp !== 1, if not evaluated?");
200 ok(false, "if(false) evaluated");
205 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
211 var obj3 = { prop1: 1, prop2: typeof(false) };
212 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
213 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
214 ok(obj3.constructor === Object, "unexpected obj3.constructor");
220 ok(blockVar === 2, "blockVar !== 2");
222 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
223 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
225 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
226 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
227 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
228 ok(getVT(0.5) === "VT_R8", "getVT(1.5) is not VT_R8");
229 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
230 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
231 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
234 ok(tmp === 4, "2+2 !== 4");
235 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
238 ok(tmp === 4.5, "2+2.5 !== 4.5");
239 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
242 ok(tmp === 4, "1.4+2.5 !== 4");
243 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
246 ok(tmp === 2, "4-2 !== 2");
247 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
250 ok(tmp === 2.5, "4.5-2 !== 2.5");
251 ok(getVT(tmp) === "VT_R8", "getVT(4-2) !== VT_R8");
254 ok(tmp === 0-2, "-2 !== 0-2");
255 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
258 ok(tmp === 6, "2*3 !== 6");
259 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
262 ok(tmp === 7, "2*3.5 !== 7");
263 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
266 /* FIXME: the parser loses precision */
267 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
268 ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
269 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
272 ok(tmp === 2, "4/2 !== 2");
273 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
276 ok(tmp === 3, "4.5/1.5 !== 3");
277 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
280 ok(tmp === 1.5, "3/2 !== 1.5");
281 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
284 ok(tmp === 1, "3%2 = " + tmp);
287 ok(tmp ===0, "4%2 = " + tmp);
290 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
293 ok(tmp === 0, "3%true = " + tmp);
296 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
299 ok((tmp += 1) === 2, "tmp += 1 !== 2");
300 ok(tmp === 2, "tmp !== 2");
303 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
304 ok(tmp === 1, "tmp !=== 1");
307 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
308 ok(tmp === 3, "tmp !=== 3");
311 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
312 ok(tmp === 2.5, "tmp !=== 2.5");
315 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
316 ok(tmp === 1, "tmp !== 1");
319 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
322 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
325 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
327 tmp = 3 || ok(false, "second or expression called");
328 ok(tmp === 3, "3 || (...) is not 3");
331 ok(tmp === 2, "false || 2 is not 2");
333 tmp = 0 && ok(false, "second and expression called");
334 ok(tmp === 0, "0 && (...) is not 0");
336 tmp = true && "test";
337 ok(tmp === "test", "true && \"test\" is not \"test\"");
340 ok(tmp === 0, "true && 0 is not 0");
343 ok(tmp === 7, "3 | 4 !== 7");
344 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
347 ok(tmp === 3, "3.5 | 0 !== 3");
348 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
351 ok(tmp === -3, "-3.5 | 0 !== -3");
352 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
355 ok(tmp === 0, "0 | NaN = " + tmp);
358 ok(tmp === 0, "0 | NaN = " + tmp);
360 tmp = 0 | (-Infinity);
361 ok(tmp === 0, "0 | NaN = " + tmp);
364 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
365 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
368 ok(tmp === 1, "3 & 5 !== 1");
369 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
372 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
373 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
375 tmp = (-3.5) & 0xffffffff;
376 ok(tmp === -3, "-3.5 & 0xffff !== -3");
377 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
380 ok(tmp === 16, "2 << 3 = " + tmp);
383 ok(tmp === 16, "2 << 35 = " + tmp);
386 ok(tmp === 2, "8 >> 2 = " + tmp);
389 ok(tmp === -4, "-64 >> 4 = " + tmp);
392 ok(tmp === 2, "8 >> 2 = " + tmp);
395 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
398 ok(tmp === 4, "4 >>> NaN = " + tmp);
401 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
402 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
405 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
406 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
409 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
410 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
413 ok(tmp === -2, "~1 !== -2");
414 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
416 ok((3,4) === 4, "(3,4) !== 4");
418 ok(+3 === 3, "+3 !== 3");
419 ok(+true === 1, "+true !== 1");
420 ok(+false === 0, "+false !== 0");
421 ok(+null === 0, "+null !== 0");
422 ok(+"0" === 0, "+'0' !== 0");
423 ok(+"3" === 3, "+'3' !== 3");
424 ok(+"-3" === -3, "+'-3' !== -3");
425 ok(+"0xff" === 255, "+'0xff' !== 255");
426 ok(+"3e3" === 3000, "+'3e3' !== 3000");
429 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
430 ok(tmp.constructor === Number, "unexpected tmp.constructor");
431 tmp = new String("1");
432 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
433 ok(tmp.constructor === String, "unexpected tmp.constructor");
435 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
436 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
437 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
438 ok("" + null === "null", "\"\" + null !== \"null\"");
439 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
440 ok("" + true === "true", "\"\" + true !== \"true\"");
441 ok("" + false === "false", "\"\" + false !== \"false\"");
442 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
443 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
445 ok(1 < 3.4, "1 < 3.4 failed");
446 ok(!(3.4 < 1), "3.4 < 1");
447 ok("abc" < "abcd", "abc < abcd failed");
448 ok("abcd" < "abce", "abce < abce failed");
449 ok("" < "x", "\"\" < \"x\" failed");
450 ok(!(0 < 0), "0 < 0");
452 ok(1 <= 3.4, "1 <= 3.4 failed");
453 ok(!(3.4 <= 1), "3.4 <= 1");
454 ok("abc" <= "abcd", "abc <= abcd failed");
455 ok("abcd" <= "abce", "abce <= abce failed");
456 ok("" <= "x", "\"\" <= \"x\" failed");
457 ok(0 <= 0, "0 <= 0 failed");
459 ok(3.4 > 1, "3.4 > 1 failed");
460 ok(!(1 > 3.4), "1 > 3.4");
461 ok("abcd" > "abc", "abc > abcd failed");
462 ok("abce" > "abcd", "abce > abce failed");
463 ok("x" > "", "\"x\" > \"\" failed");
464 ok(!(0 > 0), "0 > 0");
466 ok(3.4 >= 1, "3.4 >= 1 failed");
467 ok(!(1 >= 3.4), "1 >= 3.4");
468 ok("abcd" >= "abc", "abc >= abcd failed");
469 ok("abce" >= "abcd", "abce >= abce failed");
470 ok("x" >= "", "\"x\" >= \"\" failed");
471 ok(0 >= 0, "0 >= 0");
474 ok(++tmp === 2, "++tmp (1) is not 2");
475 ok(tmp === 2, "incremented tmp is not 2");
476 ok(--tmp === 1, "--tmp (2) is not 1");
477 ok(tmp === 1, "decremented tmp is not 1");
478 ok(tmp++ === 1, "tmp++ (1) is not 1");
479 ok(tmp === 2, "incremented tmp(1) is not 2");
480 ok(tmp-- === 2, "tmp-- (2) is not 2");
481 ok(tmp === 1, "decremented tmp is not 1");
483 String.prototype.test = true;
484 ok("".test === true, "\"\".test is not true");
486 Boolean.prototype.test = true;
487 ok(true.test === true, "true.test is not true");
489 Number.prototype.test = true;
490 ok((0).test === true, "(0).test is not true");
491 ok((0.5).test === true, "(0.5).test is not true");
495 ok(state === "", "try: state = " + state);
498 ok(false, "unexpected catch");
500 ok(state === "try", "state = " + state + " expected try");
504 ok(state === "", "try: state = " + state);
507 ok(state === "try", "finally: state = " + state);
510 ok(state === "finally", "state = " + state + " expected finally");
514 ok(state === "", "try: state = " + state);
517 ok(false, "unexpected catch");
519 ok(state === "try", "finally: state = " + state);
522 ok(state === "finally", "state = " + state + " expected finally");
526 ok(state === "", "try: state = " + state);
530 ok(state === "try", "catch: state = " + state);
531 ok(ex === "except", "ex is not \"except\"");
534 ok(state === "catch", "state = " + state + " expected catch");
538 ok(state === "", "try: state = " + state);
542 ok(state === "try", "catch: state = " + state);
543 ok(ex === true, "ex is not true");
546 ok(state === "catch", "finally: state = " + state);
549 ok(state === "finally", "state = " + state + " expected finally");
553 ok(state === "", "try: state = " + state);
555 try { throw true; } finally {}
557 ok(state === "try", "catch: state = " + state);
558 ok(ex === true, "ex is not true");
561 ok(state === "catch", "finally: state = " + state);
564 ok(state === "finally", "state = " + state + " expected finally");
568 ok(state === "", "try: state = " + state);
570 try { throw "except"; } catch(ex) { throw true; }
572 ok(state === "try", "catch: state = " + state);
573 ok(ex === true, "ex is not true");
576 ok(state === "catch", "finally: state = " + state);
579 ok(state === "finally", "state = " + state + " expected finally");
581 function throwFunc(x) {
587 ok(state === "", "try: state = " + state);
591 ok(state === "try", "catch: state = " + state);
592 ok(ex === true, "ex is not true");
595 ok(state === "catch", "finally: state = " + state);
598 ok(state === "finally", "state = " + state + " expected finally");
603 ok(false, "unexpected case \"1\"");
605 ok(state === "", "case 1: state = " + state);
608 ok(state === "1", "default: state = " + state);
611 ok(state === "default", "case false: state = " + state);
614 ok(state === "false", "state = " + state);
620 ok(false, "unexpected case 1");
622 ok(state === "", "default: state = " + state);
625 ok(state === "default", "case false: state = " + state);
628 ok(state === "false", "state = " + state);
633 ok(false, "unexpected case \"1\"");
635 ok(state === "", "case 1: state = " + state);
638 ok(state === "1", "default: state = " + state);
642 ok(false, "unexpected case false");
644 ok(state === "default", "state = " + state);
647 ok(tmp === 1, "eval(\"1\") !== 1");
648 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
649 ok(tmp === 2, "tmp !== 2");
651 ok(eval(false) === false, "eval(false) !== false");
652 ok(eval() === undefined, "eval() !== undefined");
654 tmp = eval("1", "2");
655 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
659 ok(state === "", "try: state = " + state);
661 eval("throwFunc(true);");
663 ok(state === "try", "catch: state = " + state);
664 ok(ex === true, "ex is not true");
667 ok(state === "catch", "finally: state = " + state);
670 ok(state === "finally", "state = " + state + " expected finally");
672 tmp = [,,1,2,,,true];
673 ok(tmp.length === 7, "tmp.length !== 7");
674 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
675 ok(tmp["3"] === 2, "tmp[3] !== 2");
676 ok(tmp["6"] === true, "tmp[6] !== true");
677 ok(tmp[2] === 1, "tmp[2] !== 1");
679 ok([1,].length === 2, "[1,].length !== 2");
680 ok([,,].length === 3, "[,,].length !== 3");
681 ok([,].length === 2, "[].length != 2");
682 ok([].length === 0, "[].length != 0");
686 ok(tmp < 4, "tmp >= 4");
689 ok(tmp === 4, "tmp !== 4");
693 ok(tmp < 4, "tmp >= 4");
697 ok(false, "break did not break");
700 ok(tmp === 4, "tmp !== 4");
704 ok(tmp < 4, "tmp >= 4");
707 ok(tmp === 4, "tmp !== 4");
711 ok(tmp === 0, "tmp !=== 0");
714 ok(tmp === 1, "tmp !== 1");
718 ok(tmp < 4, "tmp >= 4");
721 ok(tmp === 4, "tmp !== 4")
728 ok(false, "break did not break");
730 ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
732 ok(tmp === 4, "tmp !== 4");
734 for(tmp=0; tmp < 4; tmp++)
735 ok(tmp < 4, "tmp = " + tmp);
736 ok(tmp === 4, "tmp !== 4");
738 for(tmp=0; tmp < 4; tmp++) {
741 ok(tmp < 2, "tmp = " + tmp);
743 ok(tmp === 2, "tmp !== 2");
745 for(tmp=0; tmp < 4; tmp++) {
748 ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
750 ok(tmp === 4, "tmp !== 4");
752 for(var fi=0; fi < 4; fi++)
753 ok(fi < 4, "fi = " + fi);
754 ok(fi === 4, "fi !== 4");
756 ok((void 1) === undefined, "(void 1) !== undefined");
758 var inobj = new Object();
760 for(var iter in inobj)
761 ok(false, "unexpected iter = " + iter);
766 ok(iter == "test", "unexpected iter = " + iter);
769 ok(tmp === 1, "for..in tmp = " + tmp);
771 function forinTestObj() {}
773 forinTestObj.prototype.test3 = true;
775 var arr = new Array();
776 inobj = new forinTestObj();
786 ok(tmp === 3, "for..in tmp = " + tmp);
787 ok(arr["test1"] === true, "arr[test1] !== true");
788 ok(arr["test2"] === true, "arr[test2] !== true");
789 ok(arr["test3"] === true, "arr[test3] !== true");
793 ok((delete tmp.test) === true, "delete returned false");
794 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
796 ok(false, "tmp has prop " + iter);
800 ok(testWith === true, "testWith !== true");
806 ok(varTest1 === undefined, "varTest1 = " + varTest1);
807 ok(varTest2 === undefined, "varTest2 = " + varTest1);
811 function varTestFunc(varTest3) {
814 ok(varTest3 === 3, "varTest3 = " + varTest3);
815 ok(varTest4 === undefined, "varTest4 = " + varTest4);
826 ok(false, "deleteTest not throwed exception?");
831 ok(false, "if evaluated");
833 ok(false, "else should be associated with nearest if statement");
837 ok(false, "if evaluated");
839 ok(true, "else should be associated with nearest if statement");
841 function instanceOfTest() {}
842 tmp = new instanceOfTest();
844 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
845 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
846 ok((tmp instanceof String) === false, "tmp is instance of String");
848 instanceOfTest.prototype = new Object();
849 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
850 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
852 ok((1 instanceof Object) === false, "1 is instance of Object");
853 ok((false instanceof Boolean) === false, "false is instance of Boolean");
854 ok(("" instanceof Object) === false, "'' is instance of Object");
857 ok((arguments instanceof Object) === true, "argument is not instance of Object");
858 ok((arguments instanceof Array) === false, "argument is not instance of Array");
859 ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
863 ok(("length" in obj) === true, "length is not in obj");
864 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
865 ok(("abc" in obj) === false, "test is in obj");
867 ok(("abc" in obj) === true, "test is not in obj");
868 ok(("1" in obj) === false, "1 is in obj");
871 ok((1 in obj) === true, "1 is not in obj");
876 ok(false, "expected exception");
878 ok(!("prop" in obj), "prop in obj");
880 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
881 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
882 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
883 ok(isNaN() === true, "isNaN() !== true");
884 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
885 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
886 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
888 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
889 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
890 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
891 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
892 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
893 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
894 ok(isFinite() === false, "isFinite() !== false");
896 ok((1 < NaN) === false, "(1 < NaN) !== false");
897 ok((1 > NaN) === false, "(1 > NaN) !== false");
898 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
899 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
900 ok((NaN < 1) === false, "(NaN < 1) !== false");
901 ok((NaN > 1) === false, "(NaN > 1) !== false");
902 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
903 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
904 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
905 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
906 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
908 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
909 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
910 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
911 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
912 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
913 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
915 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
916 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
917 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
918 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
919 ok((0 === NaN) === false, "(0 === NaN) !== false");
921 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
922 ok((NaN == NaN) === false, "(NaN === NaN) != false");
923 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
924 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
925 ok((0 == NaN) === false, "(0 === NaN) != false");
928 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
930 ok(tmp === 2, "testFunc2(1) = " + tmp);
931 function testFunc2(x) { return x+1; }
933 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
935 ok(tmp === 3, "testFunc3(1) = " + tmp);
936 tmp = function testFunc3(x) { return x+2; };
939 ok(tmp === 5, "testFunc4(1) = " + tmp);
940 tmp = function testFunc4(x) { return x+3; };
943 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
944 ok(tmp === 5, "testFunc4(1) = " + tmp);
945 tmp = function testFunc4(x) { return x+4; };
946 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
948 function testEmbededFunctions() {
949 ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
951 ok(tmp === 3, "testFunc5(1) = " + tmp);
952 tmp = function testFunc5(x) { return x+2; };
955 ok(tmp === 5, "testFunc6(1) = " + tmp);
956 tmp = function testFunc6(x) { return x+3; };
958 ok(tmp === 5, "testFunc6(1) = " + tmp);
959 tmp = function testFunc6(x) { return x+4; };
961 ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
964 testEmbededFunctions();
967 date.toString = function() { return "toString"; }
968 ok(""+date === "toString", "''+date = " + date);
969 date.toString = function() { return this; }
970 ok(""+date === ""+date.valueOf(), "''+date = " + date);
972 str = new String("test");
973 str.valueOf = function() { return "valueOf"; }
974 ok(""+str === "valueOf", "''+str = " + str);
975 str.valueOf = function() { return new Date(); }
976 ok(""+str === "test", "''+str = " + str);
978 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
980 var re = /=(\?|%3F)/g;
981 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
984 for(var i=0; i<2; i++)
986 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
988 ok(createNullBSTR() === '', "createNullBSTR() !== ''");
990 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
991 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
992 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
993 ok(nullDisp !== re, "nullDisp === re");
994 ok(nullDisp === null, "nullDisp === null");
995 ok(nullDisp == null, "nullDisp == null");
996 ok(getVT(true && nullDisp) === "VT_DISPATCH",
997 "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
998 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
999 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1000 ok(nullDisp != new Object(), "nullDisp == new Object()");
1001 ok(new Object() != nullDisp, "new Object() == nullDisp");
1002 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1003 tmp = getVT(Object(nullDisp));
1004 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1005 tmp = Object(nullDisp).toString();
1006 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1008 function do_test() {}
1009 function nosemicolon() {} nosemicolon();
1010 function () {} nosemicolon();
1013 function in_if_false() { return true; } ok(false, "!?");
1016 ok(in_if_false(), "in_if_false failed");
1018 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
1020 (function() { newValue = 1; })();
1021 ok(newValue === 1, "newValue = " + newValue);
1023 obj = {undefined: 3};
1025 /* Keep this test in the end of file */
1027 ok(undefined === 6, "undefined = " + undefined);