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);
121 function testRecFunc(x) {
122 ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
125 ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
126 ok(testRecFunc.arguments[0] === true, "testRecFunc.arguments.x = " + testRecFunc.arguments[0]);
130 testRecFunc.arguments = 5;
131 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
133 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
135 tmp = (function() {1;})();
136 ok(tmp === undefined, "tmp = " + tmp);
138 ok(tmp === 1, "tmp = " + tmp);
140 var obj1 = new Object();
141 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
142 ok(obj1.constructor === Object, "unexpected obj1.constructor");
144 obj1.func = function () {
145 ok(this === obj1, "this is not obj1");
146 ok(this.test === true, "this.test is not true");
147 ok(arguments.length === 1, "arguments.length is not 1");
148 ok(arguments["0"] === true, "arguments[0] is not true");
149 ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
154 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
156 function testConstr1() {
159 ok(this !== undefined, "this is undefined");
160 ok(arguments.length === 1, "arguments.length is not 1");
161 ok(arguments["0"] === true, "arguments[0] is not 1");
162 ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
167 testConstr1.prototype.pvar = 1;
169 var obj2 = new testConstr1(true);
170 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
171 ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
172 ok(obj2.pvar === 1, "obj2.pvar is not 1");
174 testConstr1.prototype.pvar = 2;
175 ok(obj2.pvar === 2, "obj2.pvar is not 2");
178 testConstr1.prototype.pvar = 1;
179 ok(obj2.pvar === 3, "obj2.pvar is not 3");
182 function testConstr3() {
186 obj2 = new testConstr3();
187 ok(obj1 === obj2, "obj1 != obj2");
189 function testConstr4() {
193 obj2 = new testConstr3();
194 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
196 var obj3 = new Object;
197 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
199 for(var iter in "test")
200 ok(false, "unexpected forin call, test = " + iter);
202 for(var iter in null)
203 ok(false, "unexpected forin call, test = " + iter);
205 for(var iter in false)
206 ok(false, "unexpected forin call, test = " + iter);
212 ok(false, "else evaluated");
213 ok(tmp === 1, "tmp !== 1, if not evaluated?");
217 ok(false, "if evaluated");
220 ok(tmp === 1, "tmp !== 1, if not evaluated?");
223 ok(false, "if(false) evaluated");
228 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
234 var obj3 = { prop1: 1, prop2: typeof(false) };
235 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
236 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
237 ok(obj3.constructor === Object, "unexpected obj3.constructor");
243 ok(blockVar === 2, "blockVar !== 2");
245 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
246 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
248 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
249 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
250 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
251 ok(getVT(0.5) === "VT_R8", "getVT(1.5) is not VT_R8");
252 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
253 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
254 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
257 ok(tmp === 4, "2+2 !== 4");
258 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
261 ok(tmp === 4.5, "2+2.5 !== 4.5");
262 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
265 ok(tmp === 4, "1.4+2.5 !== 4");
266 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
269 ok(tmp === 2, "4-2 !== 2");
270 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
273 ok(tmp === 2.5, "4.5-2 !== 2.5");
274 ok(getVT(tmp) === "VT_R8", "getVT(4-2) !== VT_R8");
277 ok(tmp === 0-2, "-2 !== 0-2");
278 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
281 ok(tmp === 6, "2*3 !== 6");
282 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
285 ok(tmp === 7, "2*3.5 !== 7");
286 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
289 /* FIXME: the parser loses precision */
290 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
291 ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
292 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
295 ok(tmp === 2, "4/2 !== 2");
296 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
299 ok(tmp === 3, "4.5/1.5 !== 3");
300 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
303 ok(tmp === 1.5, "3/2 !== 1.5");
304 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
307 ok(tmp === 1, "3%2 = " + tmp);
310 ok(tmp ===0, "4%2 = " + tmp);
313 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
316 ok(tmp === 0, "3%true = " + tmp);
319 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
322 ok((tmp += 1) === 2, "tmp += 1 !== 2");
323 ok(tmp === 2, "tmp !== 2");
326 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
327 ok(tmp === 1, "tmp !=== 1");
330 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
331 ok(tmp === 3, "tmp !=== 3");
334 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
335 ok(tmp === 2.5, "tmp !=== 2.5");
338 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
339 ok(tmp === 1, "tmp !== 1");
342 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
345 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
348 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
350 tmp = 3 || ok(false, "second or expression called");
351 ok(tmp === 3, "3 || (...) is not 3");
354 ok(tmp === 2, "false || 2 is not 2");
356 tmp = 0 && ok(false, "second and expression called");
357 ok(tmp === 0, "0 && (...) is not 0");
359 tmp = true && "test";
360 ok(tmp === "test", "true && \"test\" is not \"test\"");
363 ok(tmp === 0, "true && 0 is not 0");
366 ok(tmp === 7, "3 | 4 !== 7");
367 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
370 ok(tmp === 3, "3.5 | 0 !== 3");
371 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
374 ok(tmp === -3, "-3.5 | 0 !== -3");
375 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
378 ok(tmp === 0, "0 | NaN = " + tmp);
381 ok(tmp === 0, "0 | NaN = " + tmp);
383 tmp = 0 | (-Infinity);
384 ok(tmp === 0, "0 | NaN = " + tmp);
387 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
388 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
391 ok(tmp === 1, "3 & 5 !== 1");
392 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
395 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
396 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
398 tmp = (-3.5) & 0xffffffff;
399 ok(tmp === -3, "-3.5 & 0xffff !== -3");
400 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
403 ok(tmp === 16, "2 << 3 = " + tmp);
406 ok(tmp === 16, "2 << 35 = " + tmp);
409 ok(tmp === 2, "8 >> 2 = " + tmp);
412 ok(tmp === -4, "-64 >> 4 = " + tmp);
415 ok(tmp === 2, "8 >> 2 = " + tmp);
418 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
421 ok(tmp === 4, "4 >>> NaN = " + tmp);
424 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
425 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
428 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
429 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
432 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
433 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
436 ok(tmp === -2, "~1 !== -2");
437 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
439 ok((3,4) === 4, "(3,4) !== 4");
441 ok(+3 === 3, "+3 !== 3");
442 ok(+true === 1, "+true !== 1");
443 ok(+false === 0, "+false !== 0");
444 ok(+null === 0, "+null !== 0");
445 ok(+"0" === 0, "+'0' !== 0");
446 ok(+"3" === 3, "+'3' !== 3");
447 ok(+"-3" === -3, "+'-3' !== -3");
448 ok(+"0xff" === 255, "+'0xff' !== 255");
449 ok(+"3e3" === 3000, "+'3e3' !== 3000");
452 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
453 ok(tmp.constructor === Number, "unexpected tmp.constructor");
454 tmp = new String("1");
455 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
456 ok(tmp.constructor === String, "unexpected tmp.constructor");
458 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
459 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
460 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
461 ok("" + null === "null", "\"\" + null !== \"null\"");
462 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
463 ok("" + true === "true", "\"\" + true !== \"true\"");
464 ok("" + false === "false", "\"\" + false !== \"false\"");
465 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
466 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
468 ok(1 < 3.4, "1 < 3.4 failed");
469 ok(!(3.4 < 1), "3.4 < 1");
470 ok("abc" < "abcd", "abc < abcd failed");
471 ok("abcd" < "abce", "abce < abce failed");
472 ok("" < "x", "\"\" < \"x\" failed");
473 ok(!(0 < 0), "0 < 0");
475 ok(1 <= 3.4, "1 <= 3.4 failed");
476 ok(!(3.4 <= 1), "3.4 <= 1");
477 ok("abc" <= "abcd", "abc <= abcd failed");
478 ok("abcd" <= "abce", "abce <= abce failed");
479 ok("" <= "x", "\"\" <= \"x\" failed");
480 ok(0 <= 0, "0 <= 0 failed");
482 ok(3.4 > 1, "3.4 > 1 failed");
483 ok(!(1 > 3.4), "1 > 3.4");
484 ok("abcd" > "abc", "abc > abcd failed");
485 ok("abce" > "abcd", "abce > abce failed");
486 ok("x" > "", "\"x\" > \"\" failed");
487 ok(!(0 > 0), "0 > 0");
489 ok(3.4 >= 1, "3.4 >= 1 failed");
490 ok(!(1 >= 3.4), "1 >= 3.4");
491 ok("abcd" >= "abc", "abc >= abcd failed");
492 ok("abce" >= "abcd", "abce >= abce failed");
493 ok("x" >= "", "\"x\" >= \"\" failed");
494 ok(0 >= 0, "0 >= 0");
497 ok(++tmp === 2, "++tmp (1) is not 2");
498 ok(tmp === 2, "incremented tmp is not 2");
499 ok(--tmp === 1, "--tmp (2) is not 1");
500 ok(tmp === 1, "decremented tmp is not 1");
501 ok(tmp++ === 1, "tmp++ (1) is not 1");
502 ok(tmp === 2, "incremented tmp(1) is not 2");
503 ok(tmp-- === 2, "tmp-- (2) is not 2");
504 ok(tmp === 1, "decremented tmp is not 1");
506 String.prototype.test = true;
507 ok("".test === true, "\"\".test is not true");
509 Boolean.prototype.test = true;
510 ok(true.test === true, "true.test is not true");
512 Number.prototype.test = true;
513 ok((0).test === true, "(0).test is not true");
514 ok((0.5).test === true, "(0.5).test is not true");
518 ok(state === "", "try: state = " + state);
521 ok(false, "unexpected catch");
523 ok(state === "try", "state = " + state + " expected try");
527 ok(state === "", "try: state = " + state);
530 ok(state === "try", "finally: state = " + state);
533 ok(state === "finally", "state = " + state + " expected finally");
537 ok(state === "", "try: state = " + state);
540 ok(false, "unexpected catch");
542 ok(state === "try", "finally: state = " + state);
545 ok(state === "finally", "state = " + state + " expected finally");
549 ok(state === "", "try: state = " + state);
553 ok(state === "try", "catch: state = " + state);
554 ok(ex === "except", "ex is not \"except\"");
557 ok(state === "catch", "state = " + state + " expected catch");
561 ok(state === "", "try: state = " + state);
565 ok(state === "try", "catch: state = " + state);
566 ok(ex === true, "ex is not true");
569 ok(state === "catch", "finally: state = " + state);
572 ok(state === "finally", "state = " + state + " expected finally");
576 ok(state === "", "try: state = " + state);
578 try { throw true; } finally {}
580 ok(state === "try", "catch: state = " + state);
581 ok(ex === true, "ex is not true");
584 ok(state === "catch", "finally: state = " + state);
587 ok(state === "finally", "state = " + state + " expected finally");
591 ok(state === "", "try: state = " + state);
593 try { throw "except"; } catch(ex) { throw true; }
595 ok(state === "try", "catch: state = " + state);
596 ok(ex === true, "ex is not true");
599 ok(state === "catch", "finally: state = " + state);
602 ok(state === "finally", "state = " + state + " expected finally");
604 function throwFunc(x) {
610 ok(state === "", "try: state = " + state);
614 ok(state === "try", "catch: state = " + state);
615 ok(ex === true, "ex is not true");
618 ok(state === "catch", "finally: state = " + state);
621 ok(state === "finally", "state = " + state + " expected finally");
626 ok(false, "unexpected case \"1\"");
628 ok(state === "", "case 1: state = " + state);
631 ok(state === "1", "default: state = " + state);
634 ok(state === "default", "case false: state = " + state);
637 ok(state === "false", "state = " + state);
643 ok(false, "unexpected case 1");
645 ok(state === "", "default: state = " + state);
648 ok(state === "default", "case false: state = " + state);
651 ok(state === "false", "state = " + state);
656 ok(false, "unexpected case \"1\"");
658 ok(state === "", "case 1: state = " + state);
661 ok(state === "1", "default: state = " + state);
665 ok(false, "unexpected case false");
667 ok(state === "default", "state = " + state);
670 ok(tmp === 1, "eval(\"1\") !== 1");
671 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
672 ok(tmp === 2, "tmp !== 2");
674 ok(eval(false) === false, "eval(false) !== false");
675 ok(eval() === undefined, "eval() !== undefined");
677 tmp = eval("1", "2");
678 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
682 ok(state === "", "try: state = " + state);
684 eval("throwFunc(true);");
686 ok(state === "try", "catch: state = " + state);
687 ok(ex === true, "ex is not true");
690 ok(state === "catch", "finally: state = " + state);
693 ok(state === "finally", "state = " + state + " expected finally");
695 tmp = [,,1,2,,,true];
696 ok(tmp.length === 7, "tmp.length !== 7");
697 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
698 ok(tmp["3"] === 2, "tmp[3] !== 2");
699 ok(tmp["6"] === true, "tmp[6] !== true");
700 ok(tmp[2] === 1, "tmp[2] !== 1");
702 ok([1,].length === 2, "[1,].length !== 2");
703 ok([,,].length === 3, "[,,].length !== 3");
704 ok([,].length === 2, "[].length != 2");
705 ok([].length === 0, "[].length != 0");
709 ok(tmp < 4, "tmp >= 4");
712 ok(tmp === 4, "tmp !== 4");
716 ok(tmp < 4, "tmp >= 4");
720 ok(false, "break did not break");
723 ok(tmp === 4, "tmp !== 4");
727 ok(tmp < 4, "tmp >= 4");
730 ok(tmp === 4, "tmp !== 4");
734 ok(tmp === 0, "tmp !=== 0");
737 ok(tmp === 1, "tmp !== 1");
741 ok(tmp < 4, "tmp >= 4");
744 ok(tmp === 4, "tmp !== 4")
751 ok(false, "break did not break");
753 ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
755 ok(tmp === 4, "tmp !== 4");
757 for(tmp=0; tmp < 4; tmp++)
758 ok(tmp < 4, "tmp = " + tmp);
759 ok(tmp === 4, "tmp !== 4");
761 for(tmp=0; tmp < 4; tmp++) {
764 ok(tmp < 2, "tmp = " + tmp);
766 ok(tmp === 2, "tmp !== 2");
768 for(tmp=0; tmp < 4; tmp++) {
771 ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
773 ok(tmp === 4, "tmp !== 4");
775 for(var fi=0; fi < 4; fi++)
776 ok(fi < 4, "fi = " + fi);
777 ok(fi === 4, "fi !== 4");
779 ok((void 1) === undefined, "(void 1) !== undefined");
781 var inobj = new Object();
783 for(var iter in inobj)
784 ok(false, "unexpected iter = " + iter);
789 ok(iter == "test", "unexpected iter = " + iter);
792 ok(tmp === 1, "for..in tmp = " + tmp);
794 function forinTestObj() {}
796 forinTestObj.prototype.test3 = true;
798 var arr = new Array();
799 inobj = new forinTestObj();
809 ok(tmp === 3, "for..in tmp = " + tmp);
810 ok(arr["test1"] === true, "arr[test1] !== true");
811 ok(arr["test2"] === true, "arr[test2] !== true");
812 ok(arr["test3"] === true, "arr[test3] !== true");
816 ok((delete tmp.test) === true, "delete returned false");
817 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
819 ok(false, "tmp has prop " + iter);
823 ok(testWith === true, "testWith !== true");
829 ok(varTest1 === undefined, "varTest1 = " + varTest1);
830 ok(varTest2 === undefined, "varTest2 = " + varTest1);
834 function varTestFunc(varTest3) {
837 ok(varTest3 === 3, "varTest3 = " + varTest3);
838 ok(varTest4 === undefined, "varTest4 = " + varTest4);
849 ok(false, "deleteTest not throwed exception?");
854 ok(false, "if evaluated");
856 ok(false, "else should be associated with nearest if statement");
860 ok(false, "if evaluated");
862 ok(true, "else should be associated with nearest if statement");
864 function instanceOfTest() {}
865 tmp = new instanceOfTest();
867 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
868 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
869 ok((tmp instanceof String) === false, "tmp is instance of String");
871 instanceOfTest.prototype = new Object();
872 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
873 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
875 ok((1 instanceof Object) === false, "1 is instance of Object");
876 ok((false instanceof Boolean) === false, "false is instance of Boolean");
877 ok(("" instanceof Object) === false, "'' is instance of Object");
880 ok((arguments instanceof Object) === true, "argument is not instance of Object");
881 ok((arguments instanceof Array) === false, "argument is not instance of Array");
882 ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
886 ok(("length" in obj) === true, "length is not in obj");
887 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
888 ok(("abc" in obj) === false, "test is in obj");
890 ok(("abc" in obj) === true, "test is not in obj");
891 ok(("1" in obj) === false, "1 is in obj");
894 ok((1 in obj) === true, "1 is not in obj");
899 ok(false, "expected exception");
901 ok(!("prop" in obj), "prop in obj");
903 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
904 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
905 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
906 ok(isNaN() === true, "isNaN() !== true");
907 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
908 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
909 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
911 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
912 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
913 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
914 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
915 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
916 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
917 ok(isFinite() === false, "isFinite() !== false");
919 ok((1 < NaN) === false, "(1 < NaN) !== false");
920 ok((1 > NaN) === false, "(1 > NaN) !== false");
921 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
922 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
923 ok((NaN < 1) === false, "(NaN < 1) !== false");
924 ok((NaN > 1) === false, "(NaN > 1) !== false");
925 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
926 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
927 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
928 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
929 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
931 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
932 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
933 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
934 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
935 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
936 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
938 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
939 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
940 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
941 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
942 ok((0 === NaN) === false, "(0 === NaN) !== false");
944 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
945 ok((NaN == NaN) === false, "(NaN === NaN) != false");
946 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
947 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
948 ok((0 == NaN) === false, "(0 === NaN) != false");
961 ["\xf3", "\\xf3", 0xf3],
962 ["\u1234", "\\u1234", 0x1234],
967 for(i=0; i<escapeTests.length; i++) {
968 tmp = escapeTests[i][0].charCodeAt(0);
969 ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]);
973 ok(tmp === true, '!+"\v1" = ' + tmp);
975 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
977 ok(tmp === 2, "testFunc2(1) = " + tmp);
978 function testFunc2(x) { return x+1; }
980 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
982 ok(tmp === 3, "testFunc3(1) = " + tmp);
983 tmp = function testFunc3(x) { return x+2; };
986 ok(tmp === 5, "testFunc4(1) = " + tmp);
987 tmp = function testFunc4(x) { return x+3; };
990 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
991 ok(tmp === 5, "testFunc4(1) = " + tmp);
992 tmp = function testFunc4(x) { return x+4; };
993 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
995 function testEmbededFunctions() {
996 ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
998 ok(tmp === 3, "testFunc5(1) = " + tmp);
999 tmp = function testFunc5(x) { return x+2; };
1002 ok(tmp === 5, "testFunc6(1) = " + tmp);
1003 tmp = function testFunc6(x) { return x+3; };
1005 ok(tmp === 5, "testFunc6(1) = " + tmp);
1006 tmp = function testFunc6(x) { return x+4; };
1008 ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
1011 testEmbededFunctions();
1014 date.toString = function() { return "toString"; }
1015 ok(""+date === "toString", "''+date = " + date);
1016 date.toString = function() { return this; }
1017 ok(""+date === ""+date.valueOf(), "''+date = " + date);
1019 str = new String("test");
1020 str.valueOf = function() { return "valueOf"; }
1021 ok(""+str === "valueOf", "''+str = " + str);
1022 str.valueOf = function() { return new Date(); }
1023 ok(""+str === "test", "''+str = " + str);
1025 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
1027 var re = /=(\?|%3F)/g;
1028 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
1031 for(var i=0; i<2; i++)
1033 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
1035 ok(createNullBSTR() === '', "createNullBSTR() !== ''");
1037 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1038 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1039 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
1040 ok(nullDisp !== re, "nullDisp === re");
1041 ok(nullDisp === null, "nullDisp === null");
1042 ok(nullDisp == null, "nullDisp == null");
1043 ok(getVT(true && nullDisp) === "VT_DISPATCH",
1044 "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
1045 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1046 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1047 ok(nullDisp != new Object(), "nullDisp == new Object()");
1048 ok(new Object() != nullDisp, "new Object() == nullDisp");
1049 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1050 tmp = getVT(Object(nullDisp));
1051 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1052 tmp = Object(nullDisp).toString();
1053 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1055 function do_test() {}
1056 function nosemicolon() {} nosemicolon();
1057 function () {} nosemicolon();
1060 function in_if_false() { return true; } ok(false, "!?");
1063 ok(in_if_false(), "in_if_false failed");
1065 (function() { newValue = 1; })();
1066 ok(newValue === 1, "newValue = " + newValue);
1068 obj = {undefined: 3};
1070 /* Keep this test in the end of file */
1072 ok(undefined === 6, "undefined = " + undefined);
1075 ok(NaN === 6, "NaN !== 6");
1078 ok(Infinity === 6, "Infinity !== 6");
1081 ok(Math === 6, "NaN !== 6");