push 0a0aa53cd365a71ca6121b6df157ca635450378f
[wine/hacks.git] / dlls / jscript / tests / lang.js
blobc4f0194160f13fc68ad44abc0a4624086389c961
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");
39 ok(1 !== 2, "1 !== 2 is false");
40 ok(null !== undefined, "null !== undefined is false");
42 ok(1 == 1, "1 == 1 is false");
43 ok(!(1 == 2), "!(1 == 2) is false");
44 ok(1.0 == 1, "1.0 == 1 is false");
45 ok("abc" == "abc", "\"abc\" == \"abc\" is false");
46 ok(true == true, "true == true is false");
47 ok(null == null, "null == null is false");
48 ok(undefined == undefined, "undefined == undefined is false");
49 ok(undefined == null, "undefined == null is false");
50 ok(true == 1, "true == 1 is false");
51 ok(!(true == 2), "true == 2");
52 ok(0 == false, "0 == false is false");
54 ok(1 != 2, "1 != 2 is false");
55 ok(false != 1, "false != 1 is false");
57 var trueVar = true;
58 ok(trueVar, "trueVar is not true");
60 ok(ScriptEngine.length === 0, "ScriptEngine.length is not 0");
62 function testFunc1(x, y) {
63     ok(this !== undefined, "this is undefined");
64     ok(x === true, "x is not 1");
65     ok(y === "test", "y is not \"test\"");
66     ok(arguments.length === 2, "arguments.length is not 2");
67     ok(arguments["0"] === true, "arguments[0] is not true");
68     ok(arguments["1"] === "test", "arguments[1] is not \"test\"");
70     return true;
73 ok(testFunc1.length === 2, "testFunc1.length is not 2");
75 ok(Object.prototype !== undefined, "Object.prototype is undefined");
76 ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
77 ok(String.prototype !== undefined, "String.prototype is undefined");
78 ok(Array.prototype !== undefined, "Array.prototype is undefined");
79 ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
80 ok(Number.prototype !== undefined, "Number.prototype is undefined");
81 ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
82 ok(Math !== undefined, "Math is undefined");
83 ok(Math.prototype === undefined, "Math.prototype is not undefined");
84 ok(Function.prototype !== undefined, "Function.prototype is undefined");
85 ok(Function.prototype.prototype === undefined, "Function.prototype is not undefined");
86 ok(Date.prototype !== undefined, "Date.prototype is undefined");
87 ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
89 Function.prototype.test = true;
90 ok(testFunc1.test === true, "testFunc1.test !== true");
91 ok(Function.test === true, "Function.test !== true");
93 ok(typeof(0) === "number", "typeof(0) is not number");
94 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
95 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
96 ok(typeof("") === "string", "typeof(\"\") is not string");
97 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
98 ok(typeof(null) === "object", "typeof(null) is not object");
99 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
100 ok(typeof(Math) === "object", "typeof(Math) is not object");
101 ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
102 ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
103 ok(typeof(String) === "function", "typeof(String) is not function");
104 ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
105 ok(typeof(this) === "object", "typeof(this) is not object");
107 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
109 var obj1 = new Object();
110 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
111 obj1.test = true;
112 obj1.func = function () {
113     ok(this === obj1, "this is not obj1");
114     ok(this.test === true, "this.test is not true");
115     ok(arguments.length === 1, "arguments.length is not 1");
116     ok(arguments["0"] === true, "arguments[0] is not true");
118     return "test";
121 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
123 function testConstr1() {
124     this.var1 = 1;
126     ok(this !== undefined, "this is undefined");
127     ok(arguments.length === 1, "arguments.length is not 1");
128     ok(arguments["0"] === true, "arguments[0] is not 1");
130     return false;
133 testConstr1.prototype.pvar = 1;
135 var obj2 = new testConstr1(true);
136 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
137 ok(obj2.pvar === 1, "obj2.pvar is not 1");
139 testConstr1.prototype.pvar = 2;
140 ok(obj2.pvar === 2, "obj2.pvar is not 2");
142 obj2.pvar = 3;
143 testConstr1.prototype.pvar = 1;
144 ok(obj2.pvar === 3, "obj2.pvar is not 3");
146 var obj3 = new Object;
147 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
149 for(var iter in "test")
150     ok(false, "unexpected forin call, test = " + iter);
152 for(var iter in null)
153     ok(false, "unexpected forin call, test = " + iter);
155 for(var iter in false)
156     ok(false, "unexpected forin call, test = " + iter);
158 tmp = 0;
159 if(true)
160     tmp = 1;
161 else
162     ok(false, "else evaluated");
163 ok(tmp === 1, "tmp !== 1, if not evaluated?");
165 tmp = 0;
166 if(1 === 0)
167     ok(false, "if evaluated");
168 else
169     tmp = 1;
170 ok(tmp === 1, "tmp !== 1, if not evaluated?");
172 if(false)
173     ok(false, "if(false) evaluated");
175 tmp = 0;
176 if(true)
177     tmp = 1;
178 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
180 if(false) {
181 }else {
184 var obj3 = { prop1: 1,  prop2: typeof(false) };
185 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
186 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
189     var blockVar = 1;
190     blockVar = 2;
192 ok(blockVar === 2, "blockVar !== 2");
194 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
195 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
197 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
198 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
199 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
200 ok(getVT(0.5) === "VT_R8", "getVT(1.5) is not VT_R8");
201 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
202 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
203 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
205 tmp = 2+2;
206 ok(tmp === 4, "2+2 !== 4");
207 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
209 tmp = 2+2.5;
210 ok(tmp === 4.5, "2+2.5 !== 4.5");
211 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
213 tmp = 1.5+2.5;
214 ok(tmp === 4, "1.4+2.5 !== 4");
215 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
217 tmp = 4-2;
218 ok(tmp === 2, "4-2 !== 2");
219 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
221 tmp = 4.5-2;
222 ok(tmp === 2.5, "4.5-2 !== 2.5");
223 ok(getVT(tmp) === "VT_R8", "getVT(4-2) !== VT_R8");
225 tmp = -2;
226 ok(tmp === 0-2, "-2 !== 0-2");
227 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
229 tmp = 2*3;
230 ok(tmp === 6, "2*3 !== 6");
231 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
233 tmp = 2*3.5;
234 ok(tmp === 7, "2*3.5 !== 7");
235 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
237 tmp = 2.5*3.5;
238 ok(tmp === 8.75, "2.5*3.5 !== 8.75");
239 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
241 tmp = 4/2;
242 ok(tmp === 2, "4/2 !== 2");
243 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
245 tmp = 4.5/1.5;
246 ok(tmp === 3, "4.5/1.5 !== 3");
247 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
249 tmp = 3/2;
250 ok(tmp === 1.5, "3/2 !== 1.5");
251 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
253 tmp = 3%2;
254 ok(tmp === 1, "3%2 = " + tmp);
256 tmp = 4%2;
257 ok(tmp ===0, "4%2 = " + tmp);
259 tmp = 3.5%1.5;
260 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
262 tmp = 3%true;
263 ok(tmp === 0, "3%true = " + tmp);
265 tmp = "ab" + "cd";
266 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
268 tmp = 1;
269 ok((tmp += 1) === 2, "tmp += 1 !== 2");
270 ok(tmp === 2, "tmp !== 2");
272 tmp = 2;
273 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
274 ok(tmp === 1, "tmp !=== 1");
276 tmp = 2;
277 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
278 ok(tmp === 3, "tmp !=== 3");
280 tmp = 5;
281 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
282 ok(tmp === 2.5, "tmp !=== 2.5");
284 tmp = 3;
285 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
286 ok(tmp === 1, "tmp !== 1");
288 tmp = 8;
289 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
291 tmp = 8;
292 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
294 tmp = 8;
295 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
297 tmp = 3 || ok(false, "second or expression called");
298 ok(tmp === 3, "3 || (...) is not 3");
300 tmp = false || 2;
301 ok(tmp === 2, "false || 2 is not 2");
303 tmp = 0 && ok(false, "second and expression called");
304 ok(tmp === 0, "0 && (...) is not 0");
306 tmp = true && "test";
307 ok(tmp === "test", "true && \"test\" is not \"test\"");
309 tmp = true && 0;
310 ok(tmp === 0, "true && 0 is not 0");
312 tmp = 3 | 4;
313 ok(tmp === 7, "3 | 4 !== 7");
314 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
316 tmp = 3.5 | 0;
317 ok(tmp === 3, "3.5 | 0 !== 3");
318 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
320 tmp = -3.5 | 0;
321 ok(tmp === -3, "-3.5 | 0 !== -3");
322 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
324 tmp = 10;
325 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
326 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
328 tmp = 3 & 5;
329 ok(tmp === 1, "3 & 5 !== 1");
330 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
332 tmp = 3.5 & 0xffff;
333 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
334 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
336 tmp = (-3.5) & 0xffffffff;
337 ok(tmp === -3, "-3.5 & 0xffff !== -3");
338 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
340 tmp = 2 << 3;
341 ok(tmp === 16, "2 << 3 = " + tmp);
343 tmp = 2 << 35;
344 ok(tmp === 16, "2 << 35 = " + tmp);
346 tmp = 8 >> 2;
347 ok(tmp === 2, "8 >> 2 = " + tmp);
349 tmp = -64 >> 4;
350 ok(tmp === -4, "-64 >> 4 = " + tmp);
352 tmp = 8 >>> 2;
353 ok(tmp === 2, "8 >> 2 = " + tmp);
355 tmp = -64 >>> 4;
356 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
358 tmp = 10;
359 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
360 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
362 tmp = 0xf0f0^0xff00;
363 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
364 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
366 tmp = 5;
367 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
368 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
370 tmp = ~1;
371 ok(tmp === -2, "~1 !== -2");
372 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
374 ok((3,4) === 4, "(3,4) !== 4");
376 ok(+3 === 3, "+3 !== 3");
377 ok(+true === 1, "+true !== 1");
378 ok(+false === 0, "+false !== 0");
379 ok(+null === 0, "+null !== 0");
380 ok(+"0" === 0, "+'0' !== 0");
381 ok(+"3" === 3, "+'3' !== 3");
382 ok(+"-3" === -3, "+'-3' !== -3");
383 ok(+"0xff" === 255, "+'0xff' !== 255");
384 ok(+"3e3" === 3000, "+'3e3' !== 3000");
386 tmp = new Number(1);
387 ok(+tmp === 1, "ToNumber(new Number(1)) = " + (+tmp));
388 tmp = new String("1");
389 ok(+tmp === 1, "ToNumber(new String('1')) = " + (+tmp));
391 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
392 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
393 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
394 ok("" + null === "null", "\"\" + null !== \"null\"");
395 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
396 ok("" + true === "true", "\"\" + true !== \"true\"");
397 ok("" + false === "false", "\"\" + false !== \"false\"");
398 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
399 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
401 ok(1 < 3.4, "1 < 3.4 failed");
402 ok(!(3.4 < 1), "3.4 < 1");
403 ok("abc" < "abcd", "abc < abcd failed");
404 ok("abcd" < "abce", "abce < abce failed");
405 ok("" < "x", "\"\" < \"x\" failed");
406 ok(!(0 < 0), "0 < 0");
408 ok(1 <= 3.4, "1 <= 3.4 failed");
409 ok(!(3.4 <= 1), "3.4 <= 1");
410 ok("abc" <= "abcd", "abc <= abcd failed");
411 ok("abcd" <= "abce", "abce <= abce failed");
412 ok("" <= "x", "\"\" <= \"x\" failed");
413 ok(0 <= 0, "0 <= 0 failed");
415 ok(3.4 > 1, "3.4 > 1 failed");
416 ok(!(1 > 3.4), "1 > 3.4");
417 ok("abcd" > "abc", "abc > abcd failed");
418 ok("abce" > "abcd", "abce > abce failed");
419 ok("x" > "", "\"x\" > \"\" failed");
420 ok(!(0 > 0), "0 > 0");
422 ok(3.4 >= 1, "3.4 >= 1 failed");
423 ok(!(1 >= 3.4), "1 >= 3.4");
424 ok("abcd" >= "abc", "abc >= abcd failed");
425 ok("abce" >= "abcd", "abce >= abce failed");
426 ok("x" >= "", "\"x\" >= \"\" failed");
427 ok(0 >= 0, "0 >= 0");
429 tmp = 1;
430 ok(++tmp === 2, "++tmp (1) is not 2");
431 ok(tmp === 2, "incremented tmp is not 2");
432 ok(--tmp === 1, "--tmp (2) is not 1");
433 ok(tmp === 1, "decremented tmp is not 1");
434 ok(tmp++ === 1, "tmp++ (1) is not 1");
435 ok(tmp === 2, "incremented tmp(1) is not 2");
436 ok(tmp-- === 2, "tmp-- (2) is not 2");
437 ok(tmp === 1, "decremented tmp is not 1");
439 String.prototype.test = true;
440 ok("".test === true, "\"\".test is not true");
442 Boolean.prototype.test = true;
443 ok(true.test === true, "true.test is not true");
445 Number.prototype.test = true;
446 ok((0).test === true, "(0).test is not true");
447 ok((0.5).test === true, "(0.5).test is not true");
449 var state = "";
450 try {
451     ok(state === "", "try: state = " + state);
452     state = "try";
453 }catch(ex) {
454     ok(false, "unexpected catch");
456 ok(state === "try", "state = " + state + " expected try");
458 state = "";
459 try {
460     ok(state === "", "try: state = " + state);
461     state = "try";
462 }finally {
463     ok(state === "try", "funally: state = " + state);
464     state = "finally";
466 ok(state === "finally", "state = " + state + " expected finally");
468 state = "";
469 try {
470     ok(state === "", "try: state = " + state);
471     state = "try";
472 }catch(ex) {
473     ok(false, "unexpected catch");
474 }finally {
475     ok(state === "try", "funally: state = " + state);
476     state = "finally";
478 ok(state === "finally", "state = " + state + " expected finally");
480 var state = "";
481 try {
482     ok(state === "", "try: state = " + state);
483     state = "try";
484     throw "except";
485 }catch(ex) {
486     ok(state === "try", "catch: state = " + state);
487     ok(ex === "except", "ex is not \"except\"");
488     state = "catch";
490 ok(state === "catch", "state = " + state + " expected catch");
492 var state = "";
493 try {
494     ok(state === "", "try: state = " + state);
495     state = "try";
496     throw true;
497 }catch(ex) {
498     ok(state === "try", "catch: state = " + state);
499     ok(ex === true, "ex is not true");
500     state = "catch";
501 }finally {
502     ok(state === "catch", "funally: state = " + state);
503     state = "finally";
505 ok(state === "finally", "state = " + state + " expected finally");
507 var state = "";
508 try {
509     ok(state === "", "try: state = " + state);
510     state = "try";
511     try { throw true; } finally {}
512 }catch(ex) {
513     ok(state === "try", "catch: state = " + state);
514     ok(ex === true, "ex is not true");
515     state = "catch";
516 }finally {
517     ok(state === "catch", "funally: state = " + state);
518     state = "finally";
520 ok(state === "finally", "state = " + state + " expected finally");
522 var state = "";
523 try {
524     ok(state === "", "try: state = " + state);
525     state = "try";
526     try { throw "except"; } catch(ex) { throw true; }
527 }catch(ex) {
528     ok(state === "try", "catch: state = " + state);
529     ok(ex === true, "ex is not true");
530     state = "catch";
531 }finally {
532     ok(state === "catch", "funally: state = " + state);
533     state = "finally";
535 ok(state === "finally", "state = " + state + " expected finally");
537 function throwFunc(x) {
538     throw x;
541 var state = "";
542 try {
543     ok(state === "", "try: state = " + state);
544     state = "try";
545     throwFunc(true);
546 }catch(ex) {
547     ok(state === "try", "catch: state = " + state);
548     ok(ex === true, "ex is not true");
549     state = "catch";
550 }finally {
551     ok(state === "catch", "funally: state = " + state);
552     state = "finally";
554 ok(state === "finally", "state = " + state + " expected finally");
556 state = "";
557 switch(1) {
558 case "1":
559     ok(false, "unexpected case \"1\"");
560 case 1:
561     ok(state === "", "case 1: state = " + state);
562     state = "1";
563 default:
564     ok(state === "1", "default: state = " + state);
565     state = "default";
566 case false:
567     ok(state === "default", "case false: state = " + state);
568     state = "false";
570 ok(state === "false", "state = " + state);
572 state = "";
573 switch("") {
574 case "1":
575 case 1:
576     ok(false, "unexpected case 1");
577 default:
578     ok(state === "", "default: state = " + state);
579     state = "default";
580 case false:
581     ok(state === "default", "case false: state = " + state);
582     state = "false";
584 ok(state === "false", "state = " + state);
586 state = "";
587 switch(1) {
588 case "1":
589     ok(false, "unexpected case \"1\"");
590 case 1:
591     ok(state === "", "case 1: state = " + state);
592     state = "1";
593 default:
594     ok(state === "1", "default: state = " + state);
595     state = "default";
596     break;
597 case false:
598     ok(false, "unexpected case false");
600 ok(state === "default", "state = " + state);
602 tmp = eval("1");
603 ok(tmp === 1, "eval(\"1\") !== 1");
604 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
605 ok(tmp === 2, "tmp !== 2");
607 ok(eval(false) === false, "eval(false) !== false");
608 ok(eval() === undefined, "eval() !== undefined");
610 tmp = eval("1", "2");
611 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
613 var state = "";
614 try {
615     ok(state === "", "try: state = " + state);
616     state = "try";
617     eval("throwFunc(true);");
618 }catch(ex) {
619     ok(state === "try", "catch: state = " + state);
620     ok(ex === true, "ex is not true");
621     state = "catch";
622 }finally {
623     ok(state === "catch", "funally: state = " + state);
624     state = "finally";
626 ok(state === "finally", "state = " + state + " expected finally");
628 tmp = [,,1,2,,,true];
629 ok(tmp.length === 7, "tmp.length !== 7");
630 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
631 ok(tmp["3"] === 2, "tmp[3] !== 2");
632 ok(tmp["6"] === true, "tmp[6] !== true");
633 ok(tmp[2] === 1, "tmp[2] !== 1");
635 ok([1,].length === 2, "[1,].length !== 2");
636 ok([,,].length === 3, "[,,].length !== 3");
637 ok([,].length === 2, "[].length != 2");
638 ok([].length === 0, "[].length != 0");
640 tmp = 0;
641 while(tmp < 4) {
642     ok(tmp < 4, "tmp >= 4");
643     tmp++;
645 ok(tmp === 4, "tmp !== 4");
647 tmp = 0;
648 while(true) {
649     ok(tmp < 4, "tmp >= 4");
650     tmp++;
651     if(tmp === 4) {
652         break;
653         ok(false, "break did not break");
654     }
656 ok(tmp === 4, "tmp !== 4");
658 tmp = 0;
659 do {
660     ok(tmp < 4, "tmp >= 4");
661     tmp++;
662 } while(tmp < 4);
663 ok(tmp === 4, "tmp !== 4");
665 tmp = 0;
666 do {
667     ok(tmp === 0, "tmp !=== 0");
668     tmp++;
669 } while(false);
670 ok(tmp === 1, "tmp !== 1");
672 tmp = 0;
673 while(tmp < 4) {
674     tmp++;
675     if(tmp === 2) {
676         continue;
677         ok(false, "break did not break");
678     }
679     ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
681 ok(tmp === 4, "tmp !== 4");
683 for(tmp=0; tmp < 4; tmp++)
684     ok(tmp < 4, "tmp = " + tmp);
685 ok(tmp === 4, "tmp !== 4");
687 for(tmp=0; tmp < 4; tmp++) {
688     if(tmp === 2)
689         break;
690     ok(tmp < 2, "tmp = " + tmp);
692 ok(tmp === 2, "tmp !== 2");
694 for(tmp=0; tmp < 4; tmp++) {
695     if(tmp === 2)
696         continue;
697     ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
699 ok(tmp === 4, "tmp !== 4");
701 for(var fi=0; fi < 4; fi++)
702     ok(fi < 4, "fi = " + fi);
703 ok(fi === 4, "fi !== 4");
705 ok((void 1) === undefined, "(void 1) !== undefined");
707 var inobj = new Object();
709 for(var iter in inobj)
710     ok(false, "unexpected iter = " + iter);
712 inobj.test = true;
713 tmp = 0;
714 for(iter in inobj) {
715     ok(iter == "test", "unexpected iter = " + iter);
716     tmp++;
718 ok(tmp === 1, "for..in tmp = " + tmp);
720 function forinTestObj() {}
722 forinTestObj.prototype.test3 = true;
724 var arr = new Array();
725 inobj = new forinTestObj();
726 inobj.test1 = true;
727 inobj.test2 = true;
729 tmp = 0;
730 for(iter in inobj) {
731     arr[iter] = true;
732     tmp++;
735 ok(tmp === 3, "for..in tmp = " + tmp);
736 ok(arr["test1"] === true, "arr[test1] !== true");
737 ok(arr["test2"] === true, "arr[test2] !== true");
738 ok(arr["test3"] === true, "arr[test3] !== true");
740 tmp = new Object();
741 tmp.test = false;
742 ok((delete tmp.test) === true, "delete returned false");
743 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
744 for(iter in tmp)
745     ok(false, "tmp has prop " + iter);
747 tmp.testWith = true;
748 with(tmp)
749     ok(testWith === true, "testWith !== true");
751 if(false) {
752     var varTest1 = true;
755 ok(varTest1 === undefined, "varTest1 = " + varTest1);
756 ok(varTest2 === undefined, "varTest2 = " + varTest1);
758 var varTest2;
760 function varTestFunc(varTest3) {
761     var varTest3;
763     ok(varTest3 === 3, "varTest3 = " + varTest3);
764     ok(varTest4 === undefined, "varTest4 = " + varTest4);
766     var varTest4;
769 varTestFunc(3);
771 deleteTest = 1;
772 delete deleteTest;
773 try {
774     tmp = deleteTest;
775     ok(false, "deleteTest not throwed exception?");
776 }catch(ex) {}
778 if (false)
779     if (true)
780         ok(false, "if evaluated");
781     else
782         ok(false, "else should be associated with nearest if statement");
784 if (true)
785     if (false)
786         ok(false, "if evaluated");
787     else
788         ok(true, "else should be associated with nearest if statement");
790 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
791 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
792 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
793 ok(isNaN() === true, "isNaN() !== true");
794 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
795 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
796 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
798 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
799 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== fals");
800 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== fals");
801 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
802 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
803 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
804 ok(isFinite() === false, "isFinite() !== false");
806 ok((1 < NaN) === false, "(1 < NaN) !== false");
807 ok((1 > NaN) === false, "(1 > NaN) !== false");
808 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
809 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
810 ok((NaN < 1) === false, "(NaN < 1) !== false");
811 ok((NaN > 1) === false, "(NaN > 1) !== false");
812 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
813 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
814 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
815 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
816 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
818 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
819 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
820 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
821 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
822 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
823 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
825 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
826 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
827 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
828 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
829 ok((0 === NaN) === false, "(0 === NaN) !== false");
831 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
832 ok((NaN == NaN) === false, "(NaN === NaN) != false");
833 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
834 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
835 ok((0 == NaN) === false, "(0 === NaN) != false");
838 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
839 tmp = testFunc2(1);
840 ok(tmp === 2, "testFunc2(1) = " + tmp);
841 function testFunc2(x) { return x+1; }
843 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
844 tmp = testFunc3(1);
845 ok(tmp === 3, "testFunc3(1) = " + tmp);
846 tmp = function testFunc3(x) { return x+2; };
848 tmp = testFunc4(1);
849 ok(tmp === 5, "testFunc4(1) = " + tmp);
850 tmp = function testFunc4(x) { return x+3; };
851 tmp = testFunc4(1);
852 testFunc4 = 1;
853 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
854 ok(tmp === 5, "testFunc4(1) = " + tmp);
855 tmp = function testFunc4(x) { return x+4; };
856 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
858 function testEmbededFunctions() {
859     ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
860     tmp = testFunc5(1);
861     ok(tmp === 3, "testFunc5(1) = " + tmp);
862     tmp = function testFunc5(x) { return x+2; };
864     tmp = testFunc6(1);
865     ok(tmp === 5, "testFunc6(1) = " + tmp);
866     tmp = function testFunc6(x) { return x+3; };
867     tmp = testFunc6(1);
868     ok(tmp === 5, "testFunc6(1) = " + tmp);
869     tmp = function testFunc6(x) { return x+4; };
870     testFunc6 = 1;
871     ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
874 testEmbededFunctions();
876 reportSuccess();