push 5b1efc32b5a8acb1d5b5e60584746392dd0c436e
[wine/hacks.git] / dlls / jscript / tests / lang.js
blobb13091fa4767e5838153a0cd204a39909c955b5a
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 = 0 | NaN;
350 ok(tmp === 0, "0 | NaN = " + tmp);
352 tmp = 0 | Infinity;
353 ok(tmp === 0, "0 | NaN = " + tmp);
355 tmp = 0 | (-Infinity);
356 ok(tmp === 0, "0 | NaN = " + tmp);
358 tmp = 10;
359 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
360 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
362 tmp = 3 & 5;
363 ok(tmp === 1, "3 & 5 !== 1");
364 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
366 tmp = 3.5 & 0xffff;
367 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
368 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
370 tmp = (-3.5) & 0xffffffff;
371 ok(tmp === -3, "-3.5 & 0xffff !== -3");
372 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
374 tmp = 2 << 3;
375 ok(tmp === 16, "2 << 3 = " + tmp);
377 tmp = 2 << 35;
378 ok(tmp === 16, "2 << 35 = " + tmp);
380 tmp = 8 >> 2;
381 ok(tmp === 2, "8 >> 2 = " + tmp);
383 tmp = -64 >> 4;
384 ok(tmp === -4, "-64 >> 4 = " + tmp);
386 tmp = 8 >>> 2;
387 ok(tmp === 2, "8 >> 2 = " + tmp);
389 tmp = -64 >>> 4;
390 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
392 tmp = 4 >>> NaN;
393 ok(tmp === 4, "4 >>> NaN = " + tmp);
395 tmp = 10;
396 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
397 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
399 tmp = 0xf0f0^0xff00;
400 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
401 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
403 tmp = 5;
404 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
405 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
407 tmp = ~1;
408 ok(tmp === -2, "~1 !== -2");
409 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
411 ok((3,4) === 4, "(3,4) !== 4");
413 ok(+3 === 3, "+3 !== 3");
414 ok(+true === 1, "+true !== 1");
415 ok(+false === 0, "+false !== 0");
416 ok(+null === 0, "+null !== 0");
417 ok(+"0" === 0, "+'0' !== 0");
418 ok(+"3" === 3, "+'3' !== 3");
419 ok(+"-3" === -3, "+'-3' !== -3");
420 ok(+"0xff" === 255, "+'0xff' !== 255");
421 ok(+"3e3" === 3000, "+'3e3' !== 3000");
423 tmp = new Number(1);
424 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
425 tmp = new String("1");
426 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
428 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
429 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
430 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
431 ok("" + null === "null", "\"\" + null !== \"null\"");
432 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
433 ok("" + true === "true", "\"\" + true !== \"true\"");
434 ok("" + false === "false", "\"\" + false !== \"false\"");
435 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
436 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
438 ok(1 < 3.4, "1 < 3.4 failed");
439 ok(!(3.4 < 1), "3.4 < 1");
440 ok("abc" < "abcd", "abc < abcd failed");
441 ok("abcd" < "abce", "abce < abce failed");
442 ok("" < "x", "\"\" < \"x\" failed");
443 ok(!(0 < 0), "0 < 0");
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 failed");
452 ok(3.4 > 1, "3.4 > 1 failed");
453 ok(!(1 > 3.4), "1 > 3.4");
454 ok("abcd" > "abc", "abc > abcd failed");
455 ok("abce" > "abcd", "abce > abce failed");
456 ok("x" > "", "\"x\" > \"\" failed");
457 ok(!(0 > 0), "0 > 0");
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 tmp = 1;
467 ok(++tmp === 2, "++tmp (1) is not 2");
468 ok(tmp === 2, "incremented tmp is not 2");
469 ok(--tmp === 1, "--tmp (2) is not 1");
470 ok(tmp === 1, "decremented tmp is not 1");
471 ok(tmp++ === 1, "tmp++ (1) is not 1");
472 ok(tmp === 2, "incremented tmp(1) is not 2");
473 ok(tmp-- === 2, "tmp-- (2) is not 2");
474 ok(tmp === 1, "decremented tmp is not 1");
476 String.prototype.test = true;
477 ok("".test === true, "\"\".test is not true");
479 Boolean.prototype.test = true;
480 ok(true.test === true, "true.test is not true");
482 Number.prototype.test = true;
483 ok((0).test === true, "(0).test is not true");
484 ok((0.5).test === true, "(0.5).test is not true");
486 var state = "";
487 try {
488     ok(state === "", "try: state = " + state);
489     state = "try";
490 }catch(ex) {
491     ok(false, "unexpected catch");
493 ok(state === "try", "state = " + state + " expected try");
495 state = "";
496 try {
497     ok(state === "", "try: state = " + state);
498     state = "try";
499 }finally {
500     ok(state === "try", "finally: state = " + state);
501     state = "finally";
503 ok(state === "finally", "state = " + state + " expected finally");
505 state = "";
506 try {
507     ok(state === "", "try: state = " + state);
508     state = "try";
509 }catch(ex) {
510     ok(false, "unexpected catch");
511 }finally {
512     ok(state === "try", "finally: state = " + state);
513     state = "finally";
515 ok(state === "finally", "state = " + state + " expected finally");
517 var state = "";
518 try {
519     ok(state === "", "try: state = " + state);
520     state = "try";
521     throw "except";
522 }catch(ex) {
523     ok(state === "try", "catch: state = " + state);
524     ok(ex === "except", "ex is not \"except\"");
525     state = "catch";
527 ok(state === "catch", "state = " + state + " expected catch");
529 var state = "";
530 try {
531     ok(state === "", "try: state = " + state);
532     state = "try";
533     throw true;
534 }catch(ex) {
535     ok(state === "try", "catch: state = " + state);
536     ok(ex === true, "ex is not true");
537     state = "catch";
538 }finally {
539     ok(state === "catch", "finally: state = " + state);
540     state = "finally";
542 ok(state === "finally", "state = " + state + " expected finally");
544 var state = "";
545 try {
546     ok(state === "", "try: state = " + state);
547     state = "try";
548     try { throw true; } finally {}
549 }catch(ex) {
550     ok(state === "try", "catch: state = " + state);
551     ok(ex === true, "ex is not true");
552     state = "catch";
553 }finally {
554     ok(state === "catch", "finally: state = " + state);
555     state = "finally";
557 ok(state === "finally", "state = " + state + " expected finally");
559 var state = "";
560 try {
561     ok(state === "", "try: state = " + state);
562     state = "try";
563     try { throw "except"; } catch(ex) { throw true; }
564 }catch(ex) {
565     ok(state === "try", "catch: state = " + state);
566     ok(ex === true, "ex is not true");
567     state = "catch";
568 }finally {
569     ok(state === "catch", "finally: state = " + state);
570     state = "finally";
572 ok(state === "finally", "state = " + state + " expected finally");
574 function throwFunc(x) {
575     throw x;
578 var state = "";
579 try {
580     ok(state === "", "try: state = " + state);
581     state = "try";
582     throwFunc(true);
583 }catch(ex) {
584     ok(state === "try", "catch: state = " + state);
585     ok(ex === true, "ex is not true");
586     state = "catch";
587 }finally {
588     ok(state === "catch", "finally: state = " + state);
589     state = "finally";
591 ok(state === "finally", "state = " + state + " expected finally");
593 state = "";
594 switch(1) {
595 case "1":
596     ok(false, "unexpected case \"1\"");
597 case 1:
598     ok(state === "", "case 1: state = " + state);
599     state = "1";
600 default:
601     ok(state === "1", "default: state = " + state);
602     state = "default";
603 case false:
604     ok(state === "default", "case false: state = " + state);
605     state = "false";
607 ok(state === "false", "state = " + state);
609 state = "";
610 switch("") {
611 case "1":
612 case 1:
613     ok(false, "unexpected case 1");
614 default:
615     ok(state === "", "default: state = " + state);
616     state = "default";
617 case false:
618     ok(state === "default", "case false: state = " + state);
619     state = "false";
621 ok(state === "false", "state = " + state);
623 state = "";
624 switch(1) {
625 case "1":
626     ok(false, "unexpected case \"1\"");
627 case 1:
628     ok(state === "", "case 1: state = " + state);
629     state = "1";
630 default:
631     ok(state === "1", "default: state = " + state);
632     state = "default";
633     break;
634 case false:
635     ok(false, "unexpected case false");
637 ok(state === "default", "state = " + state);
639 tmp = eval("1");
640 ok(tmp === 1, "eval(\"1\") !== 1");
641 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
642 ok(tmp === 2, "tmp !== 2");
644 ok(eval(false) === false, "eval(false) !== false");
645 ok(eval() === undefined, "eval() !== undefined");
647 tmp = eval("1", "2");
648 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
650 var state = "";
651 try {
652     ok(state === "", "try: state = " + state);
653     state = "try";
654     eval("throwFunc(true);");
655 }catch(ex) {
656     ok(state === "try", "catch: state = " + state);
657     ok(ex === true, "ex is not true");
658     state = "catch";
659 }finally {
660     ok(state === "catch", "finally: state = " + state);
661     state = "finally";
663 ok(state === "finally", "state = " + state + " expected finally");
665 tmp = [,,1,2,,,true];
666 ok(tmp.length === 7, "tmp.length !== 7");
667 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
668 ok(tmp["3"] === 2, "tmp[3] !== 2");
669 ok(tmp["6"] === true, "tmp[6] !== true");
670 ok(tmp[2] === 1, "tmp[2] !== 1");
672 ok([1,].length === 2, "[1,].length !== 2");
673 ok([,,].length === 3, "[,,].length !== 3");
674 ok([,].length === 2, "[].length != 2");
675 ok([].length === 0, "[].length != 0");
677 tmp = 0;
678 while(tmp < 4) {
679     ok(tmp < 4, "tmp >= 4");
680     tmp++;
682 ok(tmp === 4, "tmp !== 4");
684 tmp = 0;
685 while(true) {
686     ok(tmp < 4, "tmp >= 4");
687     tmp++;
688     if(tmp === 4) {
689         break;
690         ok(false, "break did not break");
691     }
693 ok(tmp === 4, "tmp !== 4");
695 tmp = 0;
696 do {
697     ok(tmp < 4, "tmp >= 4");
698     tmp++;
699 } while(tmp < 4);
700 ok(tmp === 4, "tmp !== 4");
702 tmp = 0;
703 do {
704     ok(tmp === 0, "tmp !=== 0");
705     tmp++;
706 } while(false);
707 ok(tmp === 1, "tmp !== 1");
709 tmp = 0;
710 do {
711     ok(tmp < 4, "tmp >= 4");
712     tmp++;
713 } while(tmp < 4)
714 ok(tmp === 4, "tmp !== 4")
716 tmp = 0;
717 while(tmp < 4) {
718     tmp++;
719     if(tmp === 2) {
720         continue;
721         ok(false, "break did not break");
722     }
723     ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
725 ok(tmp === 4, "tmp !== 4");
727 for(tmp=0; tmp < 4; tmp++)
728     ok(tmp < 4, "tmp = " + tmp);
729 ok(tmp === 4, "tmp !== 4");
731 for(tmp=0; tmp < 4; tmp++) {
732     if(tmp === 2)
733         break;
734     ok(tmp < 2, "tmp = " + tmp);
736 ok(tmp === 2, "tmp !== 2");
738 for(tmp=0; tmp < 4; tmp++) {
739     if(tmp === 2)
740         continue;
741     ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
743 ok(tmp === 4, "tmp !== 4");
745 for(var fi=0; fi < 4; fi++)
746     ok(fi < 4, "fi = " + fi);
747 ok(fi === 4, "fi !== 4");
749 ok((void 1) === undefined, "(void 1) !== undefined");
751 var inobj = new Object();
753 for(var iter in inobj)
754     ok(false, "unexpected iter = " + iter);
756 inobj.test = true;
757 tmp = 0;
758 for(iter in inobj) {
759     ok(iter == "test", "unexpected iter = " + iter);
760     tmp++;
762 ok(tmp === 1, "for..in tmp = " + tmp);
764 function forinTestObj() {}
766 forinTestObj.prototype.test3 = true;
768 var arr = new Array();
769 inobj = new forinTestObj();
770 inobj.test1 = true;
771 inobj.test2 = true;
773 tmp = 0;
774 for(iter in inobj) {
775     arr[iter] = true;
776     tmp++;
779 ok(tmp === 3, "for..in tmp = " + tmp);
780 ok(arr["test1"] === true, "arr[test1] !== true");
781 ok(arr["test2"] === true, "arr[test2] !== true");
782 ok(arr["test3"] === true, "arr[test3] !== true");
784 tmp = new Object();
785 tmp.test = false;
786 ok((delete tmp.test) === true, "delete returned false");
787 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
788 for(iter in tmp)
789     ok(false, "tmp has prop " + iter);
791 tmp.testWith = true;
792 with(tmp)
793     ok(testWith === true, "testWith !== true");
795 if(false) {
796     var varTest1 = true;
799 ok(varTest1 === undefined, "varTest1 = " + varTest1);
800 ok(varTest2 === undefined, "varTest2 = " + varTest1);
802 var varTest2;
804 function varTestFunc(varTest3) {
805     var varTest3;
807     ok(varTest3 === 3, "varTest3 = " + varTest3);
808     ok(varTest4 === undefined, "varTest4 = " + varTest4);
810     var varTest4;
813 varTestFunc(3);
815 deleteTest = 1;
816 delete deleteTest;
817 try {
818     tmp = deleteTest;
819     ok(false, "deleteTest not throwed exception?");
820 }catch(ex) {}
822 if (false)
823     if (true)
824         ok(false, "if evaluated");
825     else
826         ok(false, "else should be associated with nearest if statement");
828 if (true)
829     if (false)
830         ok(false, "if evaluated");
831     else
832         ok(true, "else should be associated with nearest if statement");
834 function instanceOfTest() {}
835 tmp = new instanceOfTest();
837 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
838 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
839 ok((tmp instanceof String) === false, "tmp is instance of String");
841 instanceOfTest.prototype = new Object();
842 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
843 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
845 ok((1 instanceof Object) === false, "1 is instance of Object");
846 ok((false instanceof Boolean) === false, "false is instance of Boolean");
847 ok(("" instanceof Object) === false, "'' is instance of Object");
849 (function () {
850     ok((arguments instanceof Object) === true, "argument is not instance of Object");
851     ok((arguments instanceof Array) === false, "argument is not instance of Array");
852     ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
853 })(1,2);
855 obj = new String();
856 ok(("length" in obj) === true, "length is not in obj");
857 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
858 ok(("abc" in obj) === false, "test is in obj");
859 obj.abc = 1;
860 ok(("abc" in obj) === true, "test is not in obj");
861 ok(("1" in obj) === false, "1 is in obj");
863 obj = [1,2,3];
864 ok((1 in obj) === true, "1 is not in obj");
866 obj = new Object();
867 try {
868     obj.prop["test"];
869     ok(false, "expected exception");
870 }catch(e) {}
871 ok(!("prop" in obj), "prop in obj");
873 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
874 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
875 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
876 ok(isNaN() === true, "isNaN() !== true");
877 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
878 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
879 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
881 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
882 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
883 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
884 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
885 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
886 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
887 ok(isFinite() === false, "isFinite() !== false");
889 ok((1 < NaN) === false, "(1 < NaN) !== false");
890 ok((1 > NaN) === false, "(1 > NaN) !== false");
891 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
892 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
893 ok((NaN < 1) === false, "(NaN < 1) !== false");
894 ok((NaN > 1) === false, "(NaN > 1) !== false");
895 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
896 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
897 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
898 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
899 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
901 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
902 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
903 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
904 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
905 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
906 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
908 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
909 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
910 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
911 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
912 ok((0 === NaN) === false, "(0 === NaN) !== false");
914 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
915 ok((NaN == NaN) === false, "(NaN === NaN) != false");
916 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
917 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
918 ok((0 == NaN) === false, "(0 === NaN) != false");
921 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
922 tmp = testFunc2(1);
923 ok(tmp === 2, "testFunc2(1) = " + tmp);
924 function testFunc2(x) { return x+1; }
926 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
927 tmp = testFunc3(1);
928 ok(tmp === 3, "testFunc3(1) = " + tmp);
929 tmp = function testFunc3(x) { return x+2; };
931 tmp = testFunc4(1);
932 ok(tmp === 5, "testFunc4(1) = " + tmp);
933 tmp = function testFunc4(x) { return x+3; };
934 tmp = testFunc4(1);
935 testFunc4 = 1;
936 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
937 ok(tmp === 5, "testFunc4(1) = " + tmp);
938 tmp = function testFunc4(x) { return x+4; };
939 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
941 function testEmbededFunctions() {
942     ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
943     tmp = testFunc5(1);
944     ok(tmp === 3, "testFunc5(1) = " + tmp);
945     tmp = function testFunc5(x) { return x+2; };
947     tmp = testFunc6(1);
948     ok(tmp === 5, "testFunc6(1) = " + tmp);
949     tmp = function testFunc6(x) { return x+3; };
950     tmp = testFunc6(1);
951     ok(tmp === 5, "testFunc6(1) = " + tmp);
952     tmp = function testFunc6(x) { return x+4; };
953     testFunc6 = 1;
954     ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
957 testEmbededFunctions();
959 date = new Date();
960 date.toString = function() { return "toString"; }
961 ok(""+date === "toString", "''+date = " + date);
962 date.toString = function() { return this; }
963 ok(""+date === ""+date.valueOf(), "''+date = " + date);
965 str = new String("test");
966 str.valueOf = function() { return "valueOf"; }
967 ok(""+str === "valueOf", "''+str = " + str);
968 str.valueOf = function() { return new Date(); }
969 ok(""+str === "test", "''+str = " + str);
971 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
973 var re = /=(\?|%3F)/g;
974 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
976 tmp = new Array();
977 for(var i=0; i<2; i++)
978     tmp[i] = /b/;
979 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
981 ok(createNullBSTR() === '', "createNullBSTR() !== ''");
983 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
984 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
985 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
986 ok(nullDisp !== re, "nullDisp === re");
987 ok(nullDisp === null, "nullDisp === null");
988 ok(nullDisp == null, "nullDisp == null");
989 ok(getVT(true && nullDisp) === "VT_DISPATCH",
990    "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
991 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
992 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
993 ok(nullDisp != new Object(), "nullDisp == new Object()");
994 ok(new Object() != nullDisp, "new Object() == nullDisp");
995 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
996 tmp = getVT(Object(nullDisp));
997 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
998 tmp = Object(nullDisp).toString();
999 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1001 function do_test() {}
1002 function nosemicolon() {} nosemicolon();
1003 function () {} nosemicolon();
1005 if(false) {
1006     function in_if_false() { return true; } ok(false, "!?");
1009 ok(in_if_false(), "in_if_false failed");
1011 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
1013 (function() { newValue = 1; })();
1014 ok(newValue === 1, "newValue = " + newValue);
1016 reportSuccess();