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");
112 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
114 ok(testFunc1
.arguments
=== null, "testFunc1.arguments = " + testFunc1
.arguments
);
116 function testRecFunc(x
) {
117 ok(testRecFunc
.arguments
=== arguments
, "testRecFunc.arguments = " + testRecFunc
.arguments
);
120 ok(testRecFunc
.arguments
=== arguments
, "testRecFunc.arguments = " + testRecFunc
.arguments
);
121 ok(testRecFunc
.arguments
[0] === true, "testRecFunc.arguments.x = " + testRecFunc
.arguments
[0]);
125 testRecFunc
.arguments
= 5;
126 ok(testRecFunc
.arguments
=== null, "testRecFunc.arguments = " + testRecFunc
.arguments
);
128 ok(testRecFunc
.arguments
=== null, "testRecFunc.arguments = " + testRecFunc
.arguments
);
130 tmp
= (function() {1;})();
131 ok(tmp
=== undefined, "tmp = " + tmp
);
133 ok(tmp
=== 1, "tmp = " + tmp
);
135 var obj1
= new Object();
136 ok(typeof(obj1
) === "object", "typeof(obj1) is not object");
137 ok(obj1
.constructor === Object
, "unexpected obj1.constructor");
139 obj1
.func = function () {
140 ok(this === obj1
, "this is not obj1");
141 ok(this.test
=== true, "this.test is not true");
142 ok(arguments
.length
=== 1, "arguments.length is not 1");
143 ok(arguments
["0"] === true, "arguments[0] is not true");
144 ok(typeof(arguments
.callee
) === "function", "typeof(arguments.calee) = " + typeof(arguments
.calee
));
149 ok(obj1
.func(true) === "test", "obj1.func(true) is not \"test\"");
151 function testConstr1() {
154 ok(this !== undefined, "this is undefined");
155 ok(arguments
.length
=== 1, "arguments.length is not 1");
156 ok(arguments
["0"] === true, "arguments[0] is not 1");
157 ok(arguments
.callee
=== testConstr1
, "arguments.calee !== testConstr1");
162 testConstr1
.prototype.pvar
= 1;
164 var obj2
= new testConstr1(true);
165 ok(typeof(obj2
) === "object", "typeof(obj2) is not object");
166 ok(obj2
.constructor === testConstr1
, "unexpected obj2.constructor");
167 ok(obj2
.pvar
=== 1, "obj2.pvar is not 1");
169 testConstr1
.prototype.pvar
= 2;
170 ok(obj2
.pvar
=== 2, "obj2.pvar is not 2");
173 testConstr1
.prototype.pvar
= 1;
174 ok(obj2
.pvar
=== 3, "obj2.pvar is not 3");
177 function testConstr3() {
181 obj2
= new testConstr3();
182 ok(obj1
=== obj2
, "obj1 != obj2");
184 function testConstr4() {
188 obj2
= new testConstr3();
189 ok(typeof(obj2
) === "object", "typeof(obj2) = " + typeof(obj2
));
191 var obj3
= new Object
;
192 ok(typeof(obj3
) === "object", "typeof(obj3) is not object");
194 for(var iter
in "test")
195 ok(false, "unexpected forin call, test = " + iter
);
197 for(var iter
in null)
198 ok(false, "unexpected forin call, test = " + iter
);
200 for(var iter
in false)
201 ok(false, "unexpected forin call, test = " + iter
);
207 ok(false, "else evaluated");
208 ok(tmp
=== 1, "tmp !== 1, if not evaluated?");
212 ok(false, "if evaluated");
215 ok(tmp
=== 1, "tmp !== 1, if not evaluated?");
218 ok(false, "if(false) evaluated");
223 ok(tmp
=== 1, "tmp !== 1, if(true) not evaluated?");
229 var obj3
= { prop1
: 1, prop2
: typeof(false) };
230 ok(obj3
.prop1
=== 1, "obj3.prop1 is not 1");
231 ok(obj3
.prop2
=== "boolean", "obj3.prop2 is not \"boolean\"");
232 ok(obj3
.constructor === Object
, "unexpected obj3.constructor");
238 ok(blockVar
=== 2, "blockVar !== 2");
240 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
241 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
243 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
244 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
245 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
246 ok(getVT(0.5) === "VT_R8", "getVT(1.5) is not VT_R8");
247 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
248 ok(getVT(Math
) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
249 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
252 ok(tmp
=== 4, "2+2 !== 4");
253 ok(getVT(tmp
) === "VT_I4", "getVT(2+2) !== VT_I4");
256 ok(tmp
=== 4.5, "2+2.5 !== 4.5");
257 ok(getVT(tmp
) === "VT_R8", "getVT(2+2.5) !== VT_R8");
260 ok(tmp
=== 4, "1.4+2.5 !== 4");
261 ok(getVT(tmp
) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
264 ok(tmp
=== 2, "4-2 !== 2");
265 ok(getVT(tmp
) === "VT_I4", "getVT(4-2) !== VT_I4");
268 ok(tmp
=== 2.5, "4.5-2 !== 2.5");
269 ok(getVT(tmp
) === "VT_R8", "getVT(4-2) !== VT_R8");
272 ok(tmp
=== 0-2, "-2 !== 0-2");
273 ok(getVT(tmp
) === "VT_I4", "getVT(-2) !== VT_I4");
276 ok(tmp
=== 6, "2*3 !== 6");
277 ok(getVT(tmp
) === "VT_I4", "getVT(2*3) !== VT_I4");
280 ok(tmp
=== 7, "2*3.5 !== 7");
281 ok(getVT(tmp
) === "VT_I4", "getVT(2*3.5) !== VT_I4");
284 /* FIXME: the parser loses precision */
285 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
286 ok(tmp
> 8.749999 && tmp
< 8.750001, "2.5*3.5 !== 8.75");
287 ok(getVT(tmp
) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
290 ok(tmp
=== 2, "4/2 !== 2");
291 ok(getVT(tmp
) === "VT_I4", "getVT(4/2) !== VT_I4");
294 ok(tmp
=== 3, "4.5/1.5 !== 3");
295 ok(getVT(tmp
) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
298 ok(tmp
=== 1.5, "3/2 !== 1.5");
299 ok(getVT(tmp
) === "VT_R8", "getVT(3/2) !== VT_R8");
302 ok(tmp
=== 1, "3%2 = " + tmp
);
305 ok(tmp
===0, "4%2 = " + tmp
);
308 ok(tmp
=== 0.5, "3.5%1.5 = " + tmp
);
311 ok(tmp
=== 0, "3%true = " + tmp
);
314 ok(tmp
=== "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
317 ok((tmp
+= 1) === 2, "tmp += 1 !== 2");
318 ok(tmp
=== 2, "tmp !== 2");
321 ok((tmp
-= 1) === 1, "tmp -= 1 !== 1");
322 ok(tmp
=== 1, "tmp !=== 1");
325 ok((tmp
*= 1.5) === 3, "tmp *= 1.5 !== 3");
326 ok(tmp
=== 3, "tmp !=== 3");
329 ok((tmp
/= 2) === 2.5, "tmp /= 2 !== 2.5");
330 ok(tmp === 2.5, "tmp
!=== 2.5");
333 ok((tmp %= 2) === 1, "tmp
%= 2 !== 1");
334 ok(tmp === 1, "tmp
!== 1");
337 ok((tmp <<= 1) === 16, "tmp
<<= 1 !== 16");
340 ok((tmp >>= 1) === 4, "tmp
>>= 1 !== 4");
343 ok((tmp >>>= 1) === 4, "tmp
>>>= 1 !== 4");
345 tmp = 3 || ok(false, "second or expression called
");
346 ok(tmp === 3, "3 || (...) is not
3");
349 ok(tmp === 2, "false || 2 is not
2");
351 tmp = 0 && ok(false, "second and expression called
");
352 ok(tmp === 0, "0 && (...) is not
0");
354 tmp = true && "test
";
355 ok(tmp === "test
", "true && \"test
\" is not
\"test
\"");
358 ok(tmp === 0, "true && 0 is not
0");
361 ok(tmp === 7, "3 | 4 !== 7");
362 ok(getVT(tmp) === "VT_I4
", "getVT(3|4) = " + getVT(tmp));
365 ok(tmp === 3, "3.5 | 0 !== 3");
366 ok(getVT(tmp) === "VT_I4
", "getVT(3.5|0) = " + getVT(tmp));
369 ok(tmp === -3, "-3.5 | 0 !== -3");
370 ok(getVT(tmp) === "VT_I4
", "getVT(3.5|0) = " + getVT(tmp));
373 ok(tmp === 0, "0 | NaN
= " + tmp);
376 ok(tmp === 0, "0 | NaN
= " + tmp);
378 tmp = 0 | (-Infinity);
379 ok(tmp === 0, "0 | NaN
= " + tmp);
382 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
383 ok(getVT(tmp) === "VT_I4
", "getVT(tmp
|= 10) = " + getVT(tmp));
386 ok(tmp === 1, "3 & 5 !== 1");
387 ok(getVT(tmp) === "VT_I4
", "getVT(3|5) = " + getVT(tmp));
390 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
391 ok(getVT(tmp) === "VT_I4
", "getVT(3.5&0xffff) = " + getVT(tmp));
393 tmp = (-3.5) & 0xffffffff;
394 ok(tmp === -3, "-3.5 & 0xffff !== -3");
395 ok(getVT(tmp) === "VT_I4
", "getVT(3.5&0xffff) = " + getVT(tmp));
398 ok(tmp === 16, "2 << 3 = " + tmp);
401 ok(tmp === 16, "2 << 35 = " + tmp);
404 ok(tmp === 2, "8 >> 2 = " + tmp);
407 ok(tmp === -4, "-64 >> 4 = " + tmp);
410 ok(tmp === 2, "8 >> 2 = " + tmp);
413 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
416 ok(tmp === 4, "4 >>> NaN
= " + tmp);
419 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
420 ok(getVT(tmp) === "VT_I4
", "getVT(tmp
&= 8) = " + getVT(tmp));
423 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
424 ok(getVT(tmp) === "VT_I4
", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
427 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
428 ok(getVT(tmp) === "VT_I4
", "getVT(tmp
^= 3) = " + getVT(tmp));
431 ok(tmp === -2, "~1 !== -2");
432 ok(getVT(tmp) === "VT_I4
", "getVT(~1) = " + getVT(tmp));
434 ok((3,4) === 4, "(3,4) !== 4");
436 ok(+3 === 3, "+3 !== 3");
437 ok(+true === 1, "+true !== 1");
438 ok(+false === 0, "+false !== 0");
439 ok(+null === 0, "+null !== 0");
440 ok(+"0" === 0, "+'0' !== 0");
441 ok(+"3" === 3, "+'3' !== 3");
442 ok(+"-3" === -3, "+'-3' !== -3");
443 ok(+"0xff" === 255, "+'0xff' !== 255");
444 ok(+"3e3
" === 3000, "+'3e3' !== 3000");
447 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
448 ok(tmp.constructor === Number, "unexpected tmp
.constructor");
449 tmp = new String("1");
450 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
451 ok(tmp.constructor === String, "unexpected tmp
.constructor");
453 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
454 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
455 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
456 ok("" + null === "null", "\"\" + null !== \"null\"");
457 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
458 ok("" + true === "true", "\"\" + true !== \"true\"");
459 ok("" + false === "false", "\"\" + false !== \"false\"");
460 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
461 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
463 ok(1 < 3.4, "1 < 3.4 failed
");
464 ok(!(3.4 < 1), "3.4 < 1");
465 ok("abc
" < "abcd
", "abc
< abcd failed
");
466 ok("abcd
" < "abce
", "abce
< abce failed
");
467 ok("" < "x
", "\"\" < \"x
\" failed
");
468 ok(!(0 < 0), "0 < 0");
470 ok(1 <= 3.4, "1 <= 3.4 failed
");
471 ok(!(3.4 <= 1), "3.4 <= 1");
472 ok("abc
" <= "abcd
", "abc
<= abcd failed
");
473 ok("abcd
" <= "abce
", "abce
<= abce failed
");
474 ok("" <= "x
", "\"\" <= \"x
\" failed
");
475 ok(0 <= 0, "0 <= 0 failed
");
477 ok(3.4 > 1, "3.4 > 1 failed
");
478 ok(!(1 > 3.4), "1 > 3.4");
479 ok("abcd
" > "abc
", "abc
> abcd failed
");
480 ok("abce
" > "abcd
", "abce
> abce failed
");
481 ok("x
" > "", "\"x
\" > \"\" failed
");
482 ok(!(0 > 0), "0 > 0");
484 ok(3.4 >= 1, "3.4 >= 1 failed
");
485 ok(!(1 >= 3.4), "1 >= 3.4");
486 ok("abcd
" >= "abc
", "abc
>= abcd failed
");
487 ok("abce
" >= "abcd
", "abce
>= abce failed
");
488 ok("x
" >= "", "\"x
\" >= \"\" failed
");
489 ok(0 >= 0, "0 >= 0");
492 ok(++tmp === 2, "++tmp (1) is not
2");
493 ok(tmp === 2, "incremented tmp is not
2");
494 ok(--tmp === 1, "--tmp (2) is not
1");
495 ok(tmp === 1, "decremented tmp is not
1");
496 ok(tmp++ === 1, "tmp
++ (1) is not
1");
497 ok(tmp === 2, "incremented
tmp(1) is not
2");
498 ok(tmp-- === 2, "tmp
-- (2) is not
2");
499 ok(tmp === 1, "decremented tmp is not
1");
501 String.prototype.test = true;
502 ok("".test === true, "\"\".test is not
true");
504 Boolean.prototype.test = true;
505 ok(true.test === true, "true.test is not
true");
507 Number.prototype.test = true;
508 ok((0).test === true, "(0).test is not
true");
509 ok((0.5).test === true, "(0.5).test is not
true");
513 ok(state === "", "try: state
= " + state);
516 ok(false, "unexpected
catch");
518 ok(state === "try", "state
= " + state + " expected
try");
522 ok(state === "", "try: state
= " + state);
525 ok(state === "try", "finally: state
= " + state);
528 ok(state === "finally", "state
= " + state + " expected
finally");
532 ok(state === "", "try: state
= " + state);
535 ok(false, "unexpected
catch");
537 ok(state === "try", "finally: state
= " + state);
540 ok(state === "finally", "state
= " + state + " expected
finally");
544 ok(state === "", "try: state
= " + state);
548 ok(state === "try", "catch: state
= " + state);
549 ok(ex === "except
", "ex is not
\"except
\"");
552 ok(state === "catch", "state
= " + state + " expected
catch");
556 ok(state === "", "try: state
= " + state);
560 ok(state === "try", "catch: state
= " + state);
561 ok(ex === true, "ex is not
true");
564 ok(state === "catch", "finally: state
= " + state);
567 ok(state === "finally", "state
= " + state + " expected
finally");
571 ok(state === "", "try: state
= " + state);
573 try { throw true; } finally {}
575 ok(state === "try", "catch: state
= " + state);
576 ok(ex === true, "ex is not
true");
579 ok(state === "catch", "finally: state
= " + state);
582 ok(state === "finally", "state
= " + state + " expected
finally");
586 ok(state === "", "try: state
= " + state);
588 try { throw "except
"; } catch(ex) { throw true; }
590 ok(state === "try", "catch: state
= " + state);
591 ok(ex === true, "ex is not
true");
594 ok(state === "catch", "finally: state
= " + state);
597 ok(state === "finally", "state
= " + state + " expected
finally");
599 function throwFunc(x) {
605 ok(state === "", "try: state
= " + state);
609 ok(state === "try", "catch: state
= " + state);
610 ok(ex === true, "ex is not
true");
613 ok(state === "catch", "finally: state
= " + state);
616 ok(state === "finally", "state
= " + state + " expected
finally");
621 ok(false, "unexpected
case \"1\"");
623 ok(state === "", "case 1: state
= " + state);
626 ok(state === "1", "default: state
= " + state);
629 ok(state === "default", "case false: state
= " + state);
632 ok(state === "false", "state
= " + state);
638 ok(false, "unexpected
case 1");
640 ok(state === "", "default: state
= " + state);
643 ok(state === "default", "case false: state
= " + state);
646 ok(state === "false", "state
= " + state);
651 ok(false, "unexpected
case \"1\"");
653 ok(state === "", "case 1: state
= " + state);
656 ok(state === "1", "default: state
= " + state);
660 ok(false, "unexpected
case false");
662 ok(state === "default", "state
= " + state);
665 ok(tmp === 1, "eval(\"1\") !== 1");
666 eval("{ ok(tmp
=== 1, 'eval: tmp !== 1'); } tmp
= 2;");
667 ok(tmp === 2, "tmp
!== 2");
669 ok(eval(false) === false, "eval(false) !== false");
670 ok(eval() === undefined, "eval() !== undefined");
672 tmp = eval("1", "2");
673 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
677 ok(state === "", "try: state
= " + state);
679 eval("throwFunc(true);");
681 ok(state === "try", "catch: state
= " + state);
682 ok(ex === true, "ex is not
true");
685 ok(state === "catch", "finally: state
= " + state);
688 ok(state === "finally", "state
= " + state + " expected
finally");
690 tmp = [,,1,2,,,true];
691 ok(tmp.length === 7, "tmp
.length
!== 7");
692 ok(tmp["0"] === undefined, "tmp
[0] is not
undefined");
693 ok(tmp["3"] === 2, "tmp
[3] !== 2");
694 ok(tmp["6"] === true, "tmp
[6] !== true");
695 ok(tmp[2] === 1, "tmp
[2] !== 1");
697 ok([1,].length === 2, "[1,].length
!== 2");
698 ok([,,].length === 3, "[,,].length
!== 3");
699 ok([,].length === 2, "[].length
!= 2");
700 ok([].length === 0, "[].length
!= 0");
704 ok(tmp < 4, "tmp
>= 4");
707 ok(tmp === 4, "tmp
!== 4");
711 ok(tmp < 4, "tmp
>= 4");
715 ok(false, "break did not
break");
718 ok(tmp === 4, "tmp
!== 4");
722 ok(tmp < 4, "tmp
>= 4");
725 ok(tmp === 4, "tmp
!== 4");
729 ok(tmp === 0, "tmp
!=== 0");
732 ok(tmp === 1, "tmp
!== 1");
736 ok(tmp < 4, "tmp
>= 4");
739 ok(tmp === 4, "tmp
!== 4")
746 ok(false, "break did not
break");
748 ok(tmp <= 4 && tmp != 2, "tmp
= " + tmp);
750 ok(tmp === 4, "tmp
!== 4");
752 for(tmp=0; tmp < 4; tmp++)
753 ok(tmp < 4, "tmp
= " + tmp);
754 ok(tmp === 4, "tmp
!== 4");
756 for(tmp=0; tmp < 4; tmp++) {
759 ok(tmp < 2, "tmp
= " + tmp);
761 ok(tmp === 2, "tmp
!== 2");
763 for(tmp=0; tmp < 4; tmp++) {
766 ok(tmp < 4 && tmp != 2, "tmp
= " + tmp);
768 ok(tmp === 4, "tmp
!== 4");
770 for(var fi=0; fi < 4; fi++)
771 ok(fi < 4, "fi
= " + fi);
772 ok(fi === 4, "fi
!== 4");
774 ok((void 1) === undefined, "(void 1) !== undefined");
776 var inobj = new Object();
778 for(var iter in inobj)
779 ok(false, "unexpected iter
= " + iter);
784 ok(iter == "test
", "unexpected iter
= " + iter);
787 ok(tmp === 1, "for..in tmp
= " + tmp);
789 function forinTestObj() {}
791 forinTestObj.prototype.test3 = true;
793 var arr = new Array();
794 inobj = new forinTestObj();
804 ok(tmp === 3, "for..in tmp
= " + tmp);
805 ok(arr["test1
"] === true, "arr
[test1
] !== true");
806 ok(arr["test2
"] === true, "arr
[test2
] !== true");
807 ok(arr["test3
"] === true, "arr
[test3
] !== true");
811 ok((delete tmp.test) === true, "delete returned
false");
812 ok(typeof(tmp.test) === "undefined", "tmp
.test type
= " + typeof(tmp.test));
814 ok(false, "tmp has prop
" + iter);
818 ok(testWith === true, "testWith
!== true");
824 ok(varTest1 === undefined, "varTest1
= " + varTest1);
825 ok(varTest2 === undefined, "varTest2
= " + varTest1);
829 function varTestFunc(varTest3) {
832 ok(varTest3 === 3, "varTest3
= " + varTest3);
833 ok(varTest4 === undefined, "varTest4
= " + varTest4);
844 ok(false, "deleteTest not throwed exception
?");
849 ok(false, "if evaluated
");
851 ok(false, "else should be associated
with nearest
if statement
");
855 ok(false, "if evaluated
");
857 ok(true, "else should be associated
with nearest
if statement
");
859 function instanceOfTest() {}
860 tmp = new instanceOfTest();
862 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance
of instanceOfTest
");
863 ok((tmp instanceof Object) === true, "tmp is not instance
of Object
");
864 ok((tmp instanceof String) === false, "tmp is instance
of String
");
866 instanceOfTest.prototype = new Object();
867 ok((tmp instanceof instanceOfTest) === false, "tmp is instance
of instanceOfTest
");
868 ok((tmp instanceof Object) === true, "tmp is not instance
of Object
");
870 ok((1 instanceof Object) === false, "1 is instance
of Object
");
871 ok((false instanceof Boolean) === false, "false is instance
of Boolean
");
872 ok(("" instanceof Object) === false, "'' is instance
of Object
");
875 ok((arguments instanceof Object) === true, "argument is not instance
of Object
");
876 ok((arguments instanceof Array) === false, "argument is not instance
of Array
");
877 ok(arguments.toString() === "[object Object
]", "arguments
.toString() = " + arguments.toString());
881 ok(("length
" in obj) === true, "length is not
in obj
");
882 ok(("isPrototypeOf
" in obj) === true, "isPrototypeOf is not
in obj
");
883 ok(("abc
" in obj) === false, "test is
in obj
");
885 ok(("abc
" in obj) === true, "test is not
in obj
");
886 ok(("1" in obj) === false, "1 is
in obj
");
889 ok((1 in obj) === true, "1 is not
in obj
");
894 ok(false, "expected exception
");
896 ok(!("prop
" in obj), "prop
in obj
");
898 ok(isNaN(NaN) === true, "isNaN(NaN
) !== true");
899 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
900 ok(isNaN(Infinity) === false, "isNaN(Infinity
) !== false");
901 ok(isNaN() === true, "isNaN() !== true");
902 ok(isNaN(NaN, 0) === true, "isNaN(NaN
, 0) !== true");
903 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN
) !== false");
904 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
906 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
907 ok(isFinite(Infinity) === false, "isFinite(Infinity
) !== false");
908 ok(isFinite(-Infinity) === false, "isFinite(Infinity
) !== false");
909 ok(isFinite(NaN) === false, "isFinite(NaN
) !== false");
910 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN
) !== true");
911 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN
, 0.5) !== false");
912 ok(isFinite() === false, "isFinite() !== false");
914 ok((1 < NaN) === false, "(1 < NaN
) !== false");
915 ok((1 > NaN) === false, "(1 > NaN
) !== false");
916 ok((1 <= NaN) === false, "(1 <= NaN
) !== false");
917 ok((1 >= NaN) === false, "(1 >= NaN
) !== false");
918 ok((NaN < 1) === false, "(NaN
< 1) !== false");
919 ok((NaN > 1) === false, "(NaN
> 1) !== false");
920 ok((NaN <= 1) === false, "(NaN
<= 1) !== false");
921 ok((NaN >= 1) === false, "(NaN
>= 1) !== false");
922 ok((Infinity < 2) === false, "(Infinity
< 2) !== false");
923 ok((Infinity > 2) === true, "(Infinity
> 2) !== true");
924 ok((-Infinity < 2) === true, "(-Infinity
< 2) !== true");
926 ok(isNaN(+"test
") === true, "isNaN(+'test') !== true");
927 ok(isNaN(+"123t
") === true, "isNaN(+'123t') !== true");
928 ok(isNaN(+"Infinity x
") === true, "isNaN(+'Infinity x') !== true");
929 ok(+"Infinity
" === Infinity, "+'Infinity' !== Infinity
");
930 ok(+" Infinity
" === Infinity, "+' Infinity ' !== Infinity
");
931 ok(+"-Infinity
" === -Infinity, "+'-Infinity' !== -Infinity
");
933 ok((NaN !== NaN) === true, "(NaN
!== NaN
) !== true");
934 ok((NaN === NaN) === false, "(NaN
=== NaN
) !== false");
935 ok((Infinity !== NaN) === true, "(Infinity
!== NaN
) !== true");
936 ok((Infinity !== NaN) === true, "(Infinity
!== NaN
) !== true");
937 ok((0 === NaN) === false, "(0 === NaN
) !== false");
939 ok((NaN != NaN) === true, "(NaN
!== NaN
) != true");
940 ok((NaN == NaN) === false, "(NaN
=== NaN
) != false");
941 ok((Infinity != NaN) === true, "(Infinity
!= NaN
) !== true");
942 ok((Infinity != NaN) === true, "(Infinity
!= NaN
) !== true");
943 ok((0 == NaN) === false, "(0 === NaN
) != false");
946 ok(typeof(testFunc2) === "function", "typeof(testFunc2
) = " + typeof(testFunc2));
948 ok(tmp === 2, "testFunc2(1) = " + tmp);
949 function testFunc2(x) { return x+1; }
951 ok(typeof(testFunc3) === "function", "typeof(testFunc3
) = " + typeof(testFunc3));
953 ok(tmp === 3, "testFunc3(1) = " + tmp);
954 tmp = function testFunc3(x) { return x+2; };
957 ok(tmp === 5, "testFunc4(1) = " + tmp);
958 tmp = function testFunc4(x) { return x+3; };
961 ok(testFunc4 === 1, "testFunc4
= " + testFunc4);
962 ok(tmp === 5, "testFunc4(1) = " + tmp);
963 tmp = function testFunc4(x) { return x+4; };
964 ok(testFunc4 === 1, "testFunc4
= " + testFunc4);
966 function testEmbededFunctions() {
967 ok(typeof(testFunc5) === "function", "typeof(testFunc5
) = " + typeof(testFunc5));
969 ok(tmp === 3, "testFunc5(1) = " + tmp);
970 tmp = function testFunc5(x) { return x+2; };
973 ok(tmp === 5, "testFunc6(1) = " + tmp);
974 tmp = function testFunc6(x) { return x+3; };
976 ok(tmp === 5, "testFunc6(1) = " + tmp);
977 tmp = function testFunc6(x) { return x+4; };
979 ok(testFunc6 === 1, "testFunc4
= " + testFunc6);
982 testEmbededFunctions();
985 date.toString = function() { return "toString
"; }
986 ok(""+date === "toString
", "''+date
= " + date);
987 date.toString = function() { return this; }
988 ok(""+date === ""+date.valueOf(), "''+date
= " + date);
990 str = new String("test
");
991 str.valueOf = function() { return "valueOf
"; }
992 ok(""+str === "valueOf
", "''+str
= " + str);
993 str.valueOf = function() { return new Date(); }
994 ok(""+str === "test
", "''+str
= " + str);
996 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
998 var re = /=(\?|%3F)/g;
999 ok(re.source === "=(\\?|%3F
)", "re
.source
= " + re.source);
1002 for(var i=0; i<2; i++)
1004 ok(tmp[0] != tmp[1], "tmp
[0] == tmp
[1]");
1006 ok(createNullBSTR() === '', "createNullBSTR() !== ''");
1008 ok(getVT(nullDisp) === "VT_DISPATCH
", "getVT(nullDisp
) = " + getVT(nullDisp));
1009 ok(typeof(nullDisp) === "object
", "typeof(nullDisp
) = " + typeof(nullDisp));
1010 ok(nullDisp === nullDisp, "nullDisp
!== nullDisp
");
1011 ok(nullDisp !== re, "nullDisp
=== re
");
1012 ok(nullDisp === null, "nullDisp
=== null");
1013 ok(nullDisp == null, "nullDisp
== null");
1014 ok(getVT(true && nullDisp) === "VT_DISPATCH
",
1015 "getVT(0 && nullDisp
) = " + getVT(true && nullDisp));
1016 ok(!nullDisp === true, "!nullDisp
= " + !nullDisp);
1017 ok(String(nullDisp) === "null", "String(nullDisp
) = " + String(nullDisp));
1018 ok(nullDisp != new Object(), "nullDisp
== new Object()");
1019 ok(new Object() != nullDisp, "new Object() == nullDisp
");
1020 ok((typeof Object(nullDisp)) === "object
", "typeof Object(nullDisp
) !== 'object'");
1021 tmp = getVT(Object(nullDisp));
1022 ok(tmp === "VT_DISPATCH
", "getVT(Object(nullDisp
) = " + tmp);
1023 tmp = Object(nullDisp).toString();
1024 ok(tmp === "[object Object
]", "Object(nullDisp
).toString() = " + tmp);
1026 function do_test() {}
1027 function nosemicolon() {} nosemicolon();
1028 function () {} nosemicolon();
1031 function in_if_false() { return true; } ok(false, "!?");
1034 ok(in_if_false(), "in_if_false failed
");
1036 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist
) = " + typeof(doesnotexist));
1038 (function() { newValue = 1; })();
1039 ok(newValue === 1, "newValue
= " + newValue);
1041 obj = {undefined: 3};
1043 /* Keep this test in the end of file */
1045 ok(undefined === 6, "undefined = " + undefined);
1048 ok(NaN === 6, "NaN
!== 6");
1051 ok(Infinity === 6, "Infinity
!== 6");
1054 ok(Math === 6, "NaN
!== 6");