push 5bc4839baba05cc4333240c25295b8dd6e351557
[wine/hacks.git] / dlls / jscript / tests / lang.js
blobbd22c529e4a81734de3e419bfa8639c40974eccb
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
19 var tmp;
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");
59 var trueVar = true;
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");
73     return true;
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);
114 tmp = eval("1;");
115 ok(tmp === 1, "tmp = " + tmp);
117 var obj1 = new Object();
118 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
119 obj1.test = true;
120 obj1.func = function () {
121     ok(this === obj1, "this is not obj1");
122     ok(this.test === true, "this.test is not true");
123     ok(arguments.length === 1, "arguments.length is not 1");
124     ok(arguments["0"] === true, "arguments[0] is not true");
125     ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
127     return "test";
130 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
132 function testConstr1() {
133     this.var1 = 1;
135     ok(this !== undefined, "this is undefined");
136     ok(arguments.length === 1, "arguments.length is not 1");
137     ok(arguments["0"] === true, "arguments[0] is not 1");
138     ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
140     return false;
143 testConstr1.prototype.pvar = 1;
145 var obj2 = new testConstr1(true);
146 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
147 ok(obj2.pvar === 1, "obj2.pvar is not 1");
149 testConstr1.prototype.pvar = 2;
150 ok(obj2.pvar === 2, "obj2.pvar is not 2");
152 obj2.pvar = 3;
153 testConstr1.prototype.pvar = 1;
154 ok(obj2.pvar === 3, "obj2.pvar is not 3");
156 obj1 = new Object();
157 function testConstr3() {
158     return obj1;
161 obj2 = new testConstr3();
162 ok(obj1 === obj2, "obj1 != obj2");
164 function testConstr4() {
165     return 2;
168 obj2 = new testConstr3();
169 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
171 var obj3 = new Object;
172 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
174 for(var iter in "test")
175     ok(false, "unexpected forin call, test = " + iter);
177 for(var iter in null)
178     ok(false, "unexpected forin call, test = " + iter);
180 for(var iter in false)
181     ok(false, "unexpected forin call, test = " + iter);
183 tmp = 0;
184 if(true)
185     tmp = 1;
186 else
187     ok(false, "else evaluated");
188 ok(tmp === 1, "tmp !== 1, if not evaluated?");
190 tmp = 0;
191 if(1 === 0)
192     ok(false, "if evaluated");
193 else
194     tmp = 1;
195 ok(tmp === 1, "tmp !== 1, if not evaluated?");
197 if(false)
198     ok(false, "if(false) evaluated");
200 tmp = 0;
201 if(true)
202     tmp = 1;
203 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
205 if(false) {
206 }else {
209 var obj3 = { prop1: 1,  prop2: typeof(false) };
210 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
211 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
214     var blockVar = 1;
215     blockVar = 2;
217 ok(blockVar === 2, "blockVar !== 2");
219 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
220 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
222 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
223 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
224 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
225 ok(getVT(0.5) === "VT_R8", "getVT(1.5) is not VT_R8");
226 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
227 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
228 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
230 tmp = 2+2;
231 ok(tmp === 4, "2+2 !== 4");
232 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
234 tmp = 2+2.5;
235 ok(tmp === 4.5, "2+2.5 !== 4.5");
236 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
238 tmp = 1.5+2.5;
239 ok(tmp === 4, "1.4+2.5 !== 4");
240 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
242 tmp = 4-2;
243 ok(tmp === 2, "4-2 !== 2");
244 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
246 tmp = 4.5-2;
247 ok(tmp === 2.5, "4.5-2 !== 2.5");
248 ok(getVT(tmp) === "VT_R8", "getVT(4-2) !== VT_R8");
250 tmp = -2;
251 ok(tmp === 0-2, "-2 !== 0-2");
252 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
254 tmp = 2*3;
255 ok(tmp === 6, "2*3 !== 6");
256 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
258 tmp = 2*3.5;
259 ok(tmp === 7, "2*3.5 !== 7");
260 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
262 tmp = 2.5*3.5;
263 ok(tmp === 8.75, "2.5*3.5 !== 8.75");
264 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
266 tmp = 4/2;
267 ok(tmp === 2, "4/2 !== 2");
268 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
270 tmp = 4.5/1.5;
271 ok(tmp === 3, "4.5/1.5 !== 3");
272 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
274 tmp = 3/2;
275 ok(tmp === 1.5, "3/2 !== 1.5");
276 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
278 tmp = 3%2;
279 ok(tmp === 1, "3%2 = " + tmp);
281 tmp = 4%2;
282 ok(tmp ===0, "4%2 = " + tmp);
284 tmp = 3.5%1.5;
285 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
287 tmp = 3%true;
288 ok(tmp === 0, "3%true = " + tmp);
290 tmp = "ab" + "cd";
291 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
293 tmp = 1;
294 ok((tmp += 1) === 2, "tmp += 1 !== 2");
295 ok(tmp === 2, "tmp !== 2");
297 tmp = 2;
298 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
299 ok(tmp === 1, "tmp !=== 1");
301 tmp = 2;
302 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
303 ok(tmp === 3, "tmp !=== 3");
305 tmp = 5;
306 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
307 ok(tmp === 2.5, "tmp !=== 2.5");
309 tmp = 3;
310 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
311 ok(tmp === 1, "tmp !== 1");
313 tmp = 8;
314 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
316 tmp = 8;
317 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
319 tmp = 8;
320 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
322 tmp = 3 || ok(false, "second or expression called");
323 ok(tmp === 3, "3 || (...) is not 3");
325 tmp = false || 2;
326 ok(tmp === 2, "false || 2 is not 2");
328 tmp = 0 && ok(false, "second and expression called");
329 ok(tmp === 0, "0 && (...) is not 0");
331 tmp = true && "test";
332 ok(tmp === "test", "true && \"test\" is not \"test\"");
334 tmp = true && 0;
335 ok(tmp === 0, "true && 0 is not 0");
337 tmp = 3 | 4;
338 ok(tmp === 7, "3 | 4 !== 7");
339 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
341 tmp = 3.5 | 0;
342 ok(tmp === 3, "3.5 | 0 !== 3");
343 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
345 tmp = -3.5 | 0;
346 ok(tmp === -3, "-3.5 | 0 !== -3");
347 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
349 tmp = 10;
350 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
351 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
353 tmp = 3 & 5;
354 ok(tmp === 1, "3 & 5 !== 1");
355 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
357 tmp = 3.5 & 0xffff;
358 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
359 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
361 tmp = (-3.5) & 0xffffffff;
362 ok(tmp === -3, "-3.5 & 0xffff !== -3");
363 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
365 tmp = 2 << 3;
366 ok(tmp === 16, "2 << 3 = " + tmp);
368 tmp = 2 << 35;
369 ok(tmp === 16, "2 << 35 = " + tmp);
371 tmp = 8 >> 2;
372 ok(tmp === 2, "8 >> 2 = " + tmp);
374 tmp = -64 >> 4;
375 ok(tmp === -4, "-64 >> 4 = " + tmp);
377 tmp = 8 >>> 2;
378 ok(tmp === 2, "8 >> 2 = " + tmp);
380 tmp = -64 >>> 4;
381 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
383 tmp = 10;
384 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
385 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
387 tmp = 0xf0f0^0xff00;
388 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
389 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
391 tmp = 5;
392 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
393 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
395 tmp = ~1;
396 ok(tmp === -2, "~1 !== -2");
397 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
399 ok((3,4) === 4, "(3,4) !== 4");
401 ok(+3 === 3, "+3 !== 3");
402 ok(+true === 1, "+true !== 1");
403 ok(+false === 0, "+false !== 0");
404 ok(+null === 0, "+null !== 0");
405 ok(+"0" === 0, "+'0' !== 0");
406 ok(+"3" === 3, "+'3' !== 3");
407 ok(+"-3" === -3, "+'-3' !== -3");
408 ok(+"0xff" === 255, "+'0xff' !== 255");
409 ok(+"3e3" === 3000, "+'3e3' !== 3000");
411 tmp = new Number(1);
412 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
413 tmp = new String("1");
414 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
416 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
417 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
418 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
419 ok("" + null === "null", "\"\" + null !== \"null\"");
420 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
421 ok("" + true === "true", "\"\" + true !== \"true\"");
422 ok("" + false === "false", "\"\" + false !== \"false\"");
423 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
424 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
426 ok(1 < 3.4, "1 < 3.4 failed");
427 ok(!(3.4 < 1), "3.4 < 1");
428 ok("abc" < "abcd", "abc < abcd failed");
429 ok("abcd" < "abce", "abce < abce failed");
430 ok("" < "x", "\"\" < \"x\" failed");
431 ok(!(0 < 0), "0 < 0");
433 ok(1 <= 3.4, "1 <= 3.4 failed");
434 ok(!(3.4 <= 1), "3.4 <= 1");
435 ok("abc" <= "abcd", "abc <= abcd failed");
436 ok("abcd" <= "abce", "abce <= abce failed");
437 ok("" <= "x", "\"\" <= \"x\" failed");
438 ok(0 <= 0, "0 <= 0 failed");
440 ok(3.4 > 1, "3.4 > 1 failed");
441 ok(!(1 > 3.4), "1 > 3.4");
442 ok("abcd" > "abc", "abc > abcd failed");
443 ok("abce" > "abcd", "abce > abce failed");
444 ok("x" > "", "\"x\" > \"\" failed");
445 ok(!(0 > 0), "0 > 0");
447 ok(3.4 >= 1, "3.4 >= 1 failed");
448 ok(!(1 >= 3.4), "1 >= 3.4");
449 ok("abcd" >= "abc", "abc >= abcd failed");
450 ok("abce" >= "abcd", "abce >= abce failed");
451 ok("x" >= "", "\"x\" >= \"\" failed");
452 ok(0 >= 0, "0 >= 0");
454 tmp = 1;
455 ok(++tmp === 2, "++tmp (1) is not 2");
456 ok(tmp === 2, "incremented tmp is not 2");
457 ok(--tmp === 1, "--tmp (2) is not 1");
458 ok(tmp === 1, "decremented tmp is not 1");
459 ok(tmp++ === 1, "tmp++ (1) is not 1");
460 ok(tmp === 2, "incremented tmp(1) is not 2");
461 ok(tmp-- === 2, "tmp-- (2) is not 2");
462 ok(tmp === 1, "decremented tmp is not 1");
464 String.prototype.test = true;
465 ok("".test === true, "\"\".test is not true");
467 Boolean.prototype.test = true;
468 ok(true.test === true, "true.test is not true");
470 Number.prototype.test = true;
471 ok((0).test === true, "(0).test is not true");
472 ok((0.5).test === true, "(0.5).test is not true");
474 var state = "";
475 try {
476     ok(state === "", "try: state = " + state);
477     state = "try";
478 }catch(ex) {
479     ok(false, "unexpected catch");
481 ok(state === "try", "state = " + state + " expected try");
483 state = "";
484 try {
485     ok(state === "", "try: state = " + state);
486     state = "try";
487 }finally {
488     ok(state === "try", "finally: state = " + state);
489     state = "finally";
491 ok(state === "finally", "state = " + state + " expected finally");
493 state = "";
494 try {
495     ok(state === "", "try: state = " + state);
496     state = "try";
497 }catch(ex) {
498     ok(false, "unexpected catch");
499 }finally {
500     ok(state === "try", "finally: state = " + state);
501     state = "finally";
503 ok(state === "finally", "state = " + state + " expected finally");
505 var state = "";
506 try {
507     ok(state === "", "try: state = " + state);
508     state = "try";
509     throw "except";
510 }catch(ex) {
511     ok(state === "try", "catch: state = " + state);
512     ok(ex === "except", "ex is not \"except\"");
513     state = "catch";
515 ok(state === "catch", "state = " + state + " expected catch");
517 var state = "";
518 try {
519     ok(state === "", "try: state = " + state);
520     state = "try";
521     throw true;
522 }catch(ex) {
523     ok(state === "try", "catch: state = " + state);
524     ok(ex === true, "ex is not true");
525     state = "catch";
526 }finally {
527     ok(state === "catch", "finally: state = " + state);
528     state = "finally";
530 ok(state === "finally", "state = " + state + " expected finally");
532 var state = "";
533 try {
534     ok(state === "", "try: state = " + state);
535     state = "try";
536     try { throw true; } finally {}
537 }catch(ex) {
538     ok(state === "try", "catch: state = " + state);
539     ok(ex === true, "ex is not true");
540     state = "catch";
541 }finally {
542     ok(state === "catch", "finally: state = " + state);
543     state = "finally";
545 ok(state === "finally", "state = " + state + " expected finally");
547 var state = "";
548 try {
549     ok(state === "", "try: state = " + state);
550     state = "try";
551     try { throw "except"; } catch(ex) { throw true; }
552 }catch(ex) {
553     ok(state === "try", "catch: state = " + state);
554     ok(ex === true, "ex is not true");
555     state = "catch";
556 }finally {
557     ok(state === "catch", "finally: state = " + state);
558     state = "finally";
560 ok(state === "finally", "state = " + state + " expected finally");
562 function throwFunc(x) {
563     throw x;
566 var state = "";
567 try {
568     ok(state === "", "try: state = " + state);
569     state = "try";
570     throwFunc(true);
571 }catch(ex) {
572     ok(state === "try", "catch: state = " + state);
573     ok(ex === true, "ex is not true");
574     state = "catch";
575 }finally {
576     ok(state === "catch", "finally: state = " + state);
577     state = "finally";
579 ok(state === "finally", "state = " + state + " expected finally");
581 state = "";
582 switch(1) {
583 case "1":
584     ok(false, "unexpected case \"1\"");
585 case 1:
586     ok(state === "", "case 1: state = " + state);
587     state = "1";
588 default:
589     ok(state === "1", "default: state = " + state);
590     state = "default";
591 case false:
592     ok(state === "default", "case false: state = " + state);
593     state = "false";
595 ok(state === "false", "state = " + state);
597 state = "";
598 switch("") {
599 case "1":
600 case 1:
601     ok(false, "unexpected case 1");
602 default:
603     ok(state === "", "default: state = " + state);
604     state = "default";
605 case false:
606     ok(state === "default", "case false: state = " + state);
607     state = "false";
609 ok(state === "false", "state = " + state);
611 state = "";
612 switch(1) {
613 case "1":
614     ok(false, "unexpected case \"1\"");
615 case 1:
616     ok(state === "", "case 1: state = " + state);
617     state = "1";
618 default:
619     ok(state === "1", "default: state = " + state);
620     state = "default";
621     break;
622 case false:
623     ok(false, "unexpected case false");
625 ok(state === "default", "state = " + state);
627 tmp = eval("1");
628 ok(tmp === 1, "eval(\"1\") !== 1");
629 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
630 ok(tmp === 2, "tmp !== 2");
632 ok(eval(false) === false, "eval(false) !== false");
633 ok(eval() === undefined, "eval() !== undefined");
635 tmp = eval("1", "2");
636 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
638 var state = "";
639 try {
640     ok(state === "", "try: state = " + state);
641     state = "try";
642     eval("throwFunc(true);");
643 }catch(ex) {
644     ok(state === "try", "catch: state = " + state);
645     ok(ex === true, "ex is not true");
646     state = "catch";
647 }finally {
648     ok(state === "catch", "finally: state = " + state);
649     state = "finally";
651 ok(state === "finally", "state = " + state + " expected finally");
653 tmp = [,,1,2,,,true];
654 ok(tmp.length === 7, "tmp.length !== 7");
655 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
656 ok(tmp["3"] === 2, "tmp[3] !== 2");
657 ok(tmp["6"] === true, "tmp[6] !== true");
658 ok(tmp[2] === 1, "tmp[2] !== 1");
660 ok([1,].length === 2, "[1,].length !== 2");
661 ok([,,].length === 3, "[,,].length !== 3");
662 ok([,].length === 2, "[].length != 2");
663 ok([].length === 0, "[].length != 0");
665 tmp = 0;
666 while(tmp < 4) {
667     ok(tmp < 4, "tmp >= 4");
668     tmp++;
670 ok(tmp === 4, "tmp !== 4");
672 tmp = 0;
673 while(true) {
674     ok(tmp < 4, "tmp >= 4");
675     tmp++;
676     if(tmp === 4) {
677         break;
678         ok(false, "break did not break");
679     }
681 ok(tmp === 4, "tmp !== 4");
683 tmp = 0;
684 do {
685     ok(tmp < 4, "tmp >= 4");
686     tmp++;
687 } while(tmp < 4);
688 ok(tmp === 4, "tmp !== 4");
690 tmp = 0;
691 do {
692     ok(tmp === 0, "tmp !=== 0");
693     tmp++;
694 } while(false);
695 ok(tmp === 1, "tmp !== 1");
697 tmp = 0;
698 do {
699     ok(tmp < 4, "tmp >= 4");
700     tmp++;
701 } while(tmp < 4)
702 ok(tmp === 4, "tmp !== 4")
704 tmp = 0;
705 while(tmp < 4) {
706     tmp++;
707     if(tmp === 2) {
708         continue;
709         ok(false, "break did not break");
710     }
711     ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
713 ok(tmp === 4, "tmp !== 4");
715 for(tmp=0; tmp < 4; tmp++)
716     ok(tmp < 4, "tmp = " + tmp);
717 ok(tmp === 4, "tmp !== 4");
719 for(tmp=0; tmp < 4; tmp++) {
720     if(tmp === 2)
721         break;
722     ok(tmp < 2, "tmp = " + tmp);
724 ok(tmp === 2, "tmp !== 2");
726 for(tmp=0; tmp < 4; tmp++) {
727     if(tmp === 2)
728         continue;
729     ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
731 ok(tmp === 4, "tmp !== 4");
733 for(var fi=0; fi < 4; fi++)
734     ok(fi < 4, "fi = " + fi);
735 ok(fi === 4, "fi !== 4");
737 ok((void 1) === undefined, "(void 1) !== undefined");
739 var inobj = new Object();
741 for(var iter in inobj)
742     ok(false, "unexpected iter = " + iter);
744 inobj.test = true;
745 tmp = 0;
746 for(iter in inobj) {
747     ok(iter == "test", "unexpected iter = " + iter);
748     tmp++;
750 ok(tmp === 1, "for..in tmp = " + tmp);
752 function forinTestObj() {}
754 forinTestObj.prototype.test3 = true;
756 var arr = new Array();
757 inobj = new forinTestObj();
758 inobj.test1 = true;
759 inobj.test2 = true;
761 tmp = 0;
762 for(iter in inobj) {
763     arr[iter] = true;
764     tmp++;
767 ok(tmp === 3, "for..in tmp = " + tmp);
768 ok(arr["test1"] === true, "arr[test1] !== true");
769 ok(arr["test2"] === true, "arr[test2] !== true");
770 ok(arr["test3"] === true, "arr[test3] !== true");
772 tmp = new Object();
773 tmp.test = false;
774 ok((delete tmp.test) === true, "delete returned false");
775 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
776 for(iter in tmp)
777     ok(false, "tmp has prop " + iter);
779 tmp.testWith = true;
780 with(tmp)
781     ok(testWith === true, "testWith !== true");
783 if(false) {
784     var varTest1 = true;
787 ok(varTest1 === undefined, "varTest1 = " + varTest1);
788 ok(varTest2 === undefined, "varTest2 = " + varTest1);
790 var varTest2;
792 function varTestFunc(varTest3) {
793     var varTest3;
795     ok(varTest3 === 3, "varTest3 = " + varTest3);
796     ok(varTest4 === undefined, "varTest4 = " + varTest4);
798     var varTest4;
801 varTestFunc(3);
803 deleteTest = 1;
804 delete deleteTest;
805 try {
806     tmp = deleteTest;
807     ok(false, "deleteTest not throwed exception?");
808 }catch(ex) {}
810 if (false)
811     if (true)
812         ok(false, "if evaluated");
813     else
814         ok(false, "else should be associated with nearest if statement");
816 if (true)
817     if (false)
818         ok(false, "if evaluated");
819     else
820         ok(true, "else should be associated with nearest if statement");
822 function instanceOfTest() {}
823 tmp = new instanceOfTest();
825 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
826 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
827 ok((tmp instanceof String) === false, "tmp is instance of String");
829 instanceOfTest.prototype = new Object();
830 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
831 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
833 ok((1 instanceof Object) === false, "1 is instance of Object");
834 ok((false instanceof Boolean) === false, "false is instance of Boolean");
835 ok(("" instanceof Object) === false, "'' is instance of Object");
837 (function () {
838     ok((arguments instanceof Object) === true, "argument is not instance of Object");
839     ok((arguments instanceof Array) === false, "argument is not instance of Array");
840     ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
841 })(1,2);
843 obj = new String();
844 ok(("length" in obj) === true, "length is not in obj");
845 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
846 ok(("abc" in obj) === false, "test is in obj");
847 obj.abc = 1;
848 ok(("abc" in obj) === true, "test is not in obj");
849 ok(("1" in obj) === false, "1 is in obj");
851 obj = [1,2,3];
852 ok((1 in obj) === true, "1 is not in obj");
854 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
855 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
856 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
857 ok(isNaN() === true, "isNaN() !== true");
858 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
859 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
860 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
862 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
863 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
864 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
865 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
866 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
867 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
868 ok(isFinite() === false, "isFinite() !== false");
870 ok((1 < NaN) === false, "(1 < NaN) !== false");
871 ok((1 > NaN) === false, "(1 > NaN) !== false");
872 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
873 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
874 ok((NaN < 1) === false, "(NaN < 1) !== false");
875 ok((NaN > 1) === false, "(NaN > 1) !== false");
876 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
877 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
878 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
879 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
880 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
882 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
883 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
884 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
885 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
886 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
887 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
889 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
890 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
891 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
892 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
893 ok((0 === NaN) === false, "(0 === NaN) !== false");
895 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
896 ok((NaN == NaN) === false, "(NaN === NaN) != false");
897 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
898 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
899 ok((0 == NaN) === false, "(0 === NaN) != false");
902 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
903 tmp = testFunc2(1);
904 ok(tmp === 2, "testFunc2(1) = " + tmp);
905 function testFunc2(x) { return x+1; }
907 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
908 tmp = testFunc3(1);
909 ok(tmp === 3, "testFunc3(1) = " + tmp);
910 tmp = function testFunc3(x) { return x+2; };
912 tmp = testFunc4(1);
913 ok(tmp === 5, "testFunc4(1) = " + tmp);
914 tmp = function testFunc4(x) { return x+3; };
915 tmp = testFunc4(1);
916 testFunc4 = 1;
917 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
918 ok(tmp === 5, "testFunc4(1) = " + tmp);
919 tmp = function testFunc4(x) { return x+4; };
920 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
922 function testEmbededFunctions() {
923     ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
924     tmp = testFunc5(1);
925     ok(tmp === 3, "testFunc5(1) = " + tmp);
926     tmp = function testFunc5(x) { return x+2; };
928     tmp = testFunc6(1);
929     ok(tmp === 5, "testFunc6(1) = " + tmp);
930     tmp = function testFunc6(x) { return x+3; };
931     tmp = testFunc6(1);
932     ok(tmp === 5, "testFunc6(1) = " + tmp);
933     tmp = function testFunc6(x) { return x+4; };
934     testFunc6 = 1;
935     ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
938 testEmbededFunctions();
940 date = new Date();
941 date.toString = function() { return "toString"; }
942 ok(""+date === "toString", "''+date = " + date);
943 date.toString = function() { return this; }
944 ok(""+date === ""+date.valueOf(), "''+date = " + date);
946 str = new String("test");
947 str.valueOf = function() { return "valueOf"; }
948 ok(""+str === "valueOf", "''+str = " + str);
949 str.valueOf = function() { return new Date(); }
950 ok(""+str === "test", "''+str = " + str);
952 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
954 var re = /=(\?|%3F)/g;
955 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
957 tmp = new Array();
958 for(var i=0; i<2; i++)
959     tmp[i] = /b/;
960 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
962 ok(createNullBSTR() === '', "createNullBSTR() !== ''");
964 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
965 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
966 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
967 ok(nullDisp !== re, "nullDisp === re");
968 ok(nullDisp === null, "nullDisp === null");
969 ok(nullDisp == null, "nullDisp == null");
970 ok(getVT(true && nullDisp) === "VT_DISPATCH",
971    "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
972 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
973 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
974 ok(nullDisp != new Object(), "nullDisp == new Object()");
975 ok(new Object() != nullDisp, "new Object() == nullDisp");
976 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
977 tmp = getVT(Object(nullDisp));
978 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
979 tmp = Object(nullDisp).toString();
980 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
982 function do_test() {}
983 function nosemicolon() {} nosemicolon();
984 function () {} nosemicolon();
986 if(false) {
987     function in_if_false() { return true; } ok(false, "!?");
990 ok(in_if_false(), "in_if_false failed");
992 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
994 (function() { newValue = 1; })();
995 ok(newValue === 1, "newValue = " + newValue);
997 reportSuccess();