push 87b6981010d7405c33b14cddcceec21b47729eba
[wine/hacks.git] / dlls / jscript / tests / lang.js
blob495762ee5991600578d38c65acb41e5e2f656825
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 ok(obj1.constructor === Object, "unexpected obj1.constructor");
120 obj1.test = true;
121 obj1.func = function () {
122     ok(this === obj1, "this is not obj1");
123     ok(this.test === true, "this.test is not true");
124     ok(arguments.length === 1, "arguments.length is not 1");
125     ok(arguments["0"] === true, "arguments[0] is not true");
126     ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
128     return "test";
131 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
133 function testConstr1() {
134     this.var1 = 1;
136     ok(this !== undefined, "this is undefined");
137     ok(arguments.length === 1, "arguments.length is not 1");
138     ok(arguments["0"] === true, "arguments[0] is not 1");
139     ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
141     return false;
144 testConstr1.prototype.pvar = 1;
146 var obj2 = new testConstr1(true);
147 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
148 ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
149 ok(obj2.pvar === 1, "obj2.pvar is not 1");
151 testConstr1.prototype.pvar = 2;
152 ok(obj2.pvar === 2, "obj2.pvar is not 2");
154 obj2.pvar = 3;
155 testConstr1.prototype.pvar = 1;
156 ok(obj2.pvar === 3, "obj2.pvar is not 3");
158 obj1 = new Object();
159 function testConstr3() {
160     return obj1;
163 obj2 = new testConstr3();
164 ok(obj1 === obj2, "obj1 != obj2");
166 function testConstr4() {
167     return 2;
170 obj2 = new testConstr3();
171 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
173 var obj3 = new Object;
174 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
176 for(var iter in "test")
177     ok(false, "unexpected forin call, test = " + iter);
179 for(var iter in null)
180     ok(false, "unexpected forin call, test = " + iter);
182 for(var iter in false)
183     ok(false, "unexpected forin call, test = " + iter);
185 tmp = 0;
186 if(true)
187     tmp = 1;
188 else
189     ok(false, "else evaluated");
190 ok(tmp === 1, "tmp !== 1, if not evaluated?");
192 tmp = 0;
193 if(1 === 0)
194     ok(false, "if evaluated");
195 else
196     tmp = 1;
197 ok(tmp === 1, "tmp !== 1, if not evaluated?");
199 if(false)
200     ok(false, "if(false) evaluated");
202 tmp = 0;
203 if(true)
204     tmp = 1;
205 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
207 if(false) {
208 }else {
211 var obj3 = { prop1: 1,  prop2: typeof(false) };
212 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
213 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
214 ok(obj3.constructor === Object, "unexpected obj3.constructor");
217     var blockVar = 1;
218     blockVar = 2;
220 ok(blockVar === 2, "blockVar !== 2");
222 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
223 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
225 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
226 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
227 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
228 ok(getVT(0.5) === "VT_R8", "getVT(1.5) is not VT_R8");
229 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
230 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
231 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
233 tmp = 2+2;
234 ok(tmp === 4, "2+2 !== 4");
235 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
237 tmp = 2+2.5;
238 ok(tmp === 4.5, "2+2.5 !== 4.5");
239 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
241 tmp = 1.5+2.5;
242 ok(tmp === 4, "1.4+2.5 !== 4");
243 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
245 tmp = 4-2;
246 ok(tmp === 2, "4-2 !== 2");
247 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
249 tmp = 4.5-2;
250 ok(tmp === 2.5, "4.5-2 !== 2.5");
251 ok(getVT(tmp) === "VT_R8", "getVT(4-2) !== VT_R8");
253 tmp = -2;
254 ok(tmp === 0-2, "-2 !== 0-2");
255 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
257 tmp = 2*3;
258 ok(tmp === 6, "2*3 !== 6");
259 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
261 tmp = 2*3.5;
262 ok(tmp === 7, "2*3.5 !== 7");
263 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
265 tmp = 2.5*3.5;
266 ok(tmp === 8.75, "2.5*3.5 !== 8.75");
267 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
269 tmp = 4/2;
270 ok(tmp === 2, "4/2 !== 2");
271 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
273 tmp = 4.5/1.5;
274 ok(tmp === 3, "4.5/1.5 !== 3");
275 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
277 tmp = 3/2;
278 ok(tmp === 1.5, "3/2 !== 1.5");
279 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
281 tmp = 3%2;
282 ok(tmp === 1, "3%2 = " + tmp);
284 tmp = 4%2;
285 ok(tmp ===0, "4%2 = " + tmp);
287 tmp = 3.5%1.5;
288 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
290 tmp = 3%true;
291 ok(tmp === 0, "3%true = " + tmp);
293 tmp = "ab" + "cd";
294 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
296 tmp = 1;
297 ok((tmp += 1) === 2, "tmp += 1 !== 2");
298 ok(tmp === 2, "tmp !== 2");
300 tmp = 2;
301 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
302 ok(tmp === 1, "tmp !=== 1");
304 tmp = 2;
305 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
306 ok(tmp === 3, "tmp !=== 3");
308 tmp = 5;
309 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
310 ok(tmp === 2.5, "tmp !=== 2.5");
312 tmp = 3;
313 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
314 ok(tmp === 1, "tmp !== 1");
316 tmp = 8;
317 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
319 tmp = 8;
320 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
322 tmp = 8;
323 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
325 tmp = 3 || ok(false, "second or expression called");
326 ok(tmp === 3, "3 || (...) is not 3");
328 tmp = false || 2;
329 ok(tmp === 2, "false || 2 is not 2");
331 tmp = 0 && ok(false, "second and expression called");
332 ok(tmp === 0, "0 && (...) is not 0");
334 tmp = true && "test";
335 ok(tmp === "test", "true && \"test\" is not \"test\"");
337 tmp = true && 0;
338 ok(tmp === 0, "true && 0 is not 0");
340 tmp = 3 | 4;
341 ok(tmp === 7, "3 | 4 !== 7");
342 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
344 tmp = 3.5 | 0;
345 ok(tmp === 3, "3.5 | 0 !== 3");
346 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
348 tmp = -3.5 | 0;
349 ok(tmp === -3, "-3.5 | 0 !== -3");
350 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
352 tmp = 0 | NaN;
353 ok(tmp === 0, "0 | NaN = " + tmp);
355 tmp = 0 | Infinity;
356 ok(tmp === 0, "0 | NaN = " + tmp);
358 tmp = 0 | (-Infinity);
359 ok(tmp === 0, "0 | NaN = " + tmp);
361 tmp = 10;
362 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
363 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
365 tmp = 3 & 5;
366 ok(tmp === 1, "3 & 5 !== 1");
367 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
369 tmp = 3.5 & 0xffff;
370 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
371 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
373 tmp = (-3.5) & 0xffffffff;
374 ok(tmp === -3, "-3.5 & 0xffff !== -3");
375 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
377 tmp = 2 << 3;
378 ok(tmp === 16, "2 << 3 = " + tmp);
380 tmp = 2 << 35;
381 ok(tmp === 16, "2 << 35 = " + tmp);
383 tmp = 8 >> 2;
384 ok(tmp === 2, "8 >> 2 = " + tmp);
386 tmp = -64 >> 4;
387 ok(tmp === -4, "-64 >> 4 = " + tmp);
389 tmp = 8 >>> 2;
390 ok(tmp === 2, "8 >> 2 = " + tmp);
392 tmp = -64 >>> 4;
393 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
395 tmp = 4 >>> NaN;
396 ok(tmp === 4, "4 >>> NaN = " + tmp);
398 tmp = 10;
399 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
400 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
402 tmp = 0xf0f0^0xff00;
403 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
404 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
406 tmp = 5;
407 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
408 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
410 tmp = ~1;
411 ok(tmp === -2, "~1 !== -2");
412 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
414 ok((3,4) === 4, "(3,4) !== 4");
416 ok(+3 === 3, "+3 !== 3");
417 ok(+true === 1, "+true !== 1");
418 ok(+false === 0, "+false !== 0");
419 ok(+null === 0, "+null !== 0");
420 ok(+"0" === 0, "+'0' !== 0");
421 ok(+"3" === 3, "+'3' !== 3");
422 ok(+"-3" === -3, "+'-3' !== -3");
423 ok(+"0xff" === 255, "+'0xff' !== 255");
424 ok(+"3e3" === 3000, "+'3e3' !== 3000");
426 tmp = new Number(1);
427 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
428 ok(tmp.constructor === Number, "unexpected tmp.constructor");
429 tmp = new String("1");
430 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
431 ok(tmp.constructor === String, "unexpected tmp.constructor");
433 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
434 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
435 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
436 ok("" + null === "null", "\"\" + null !== \"null\"");
437 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
438 ok("" + true === "true", "\"\" + true !== \"true\"");
439 ok("" + false === "false", "\"\" + false !== \"false\"");
440 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
441 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
443 ok(1 < 3.4, "1 < 3.4 failed");
444 ok(!(3.4 < 1), "3.4 < 1");
445 ok("abc" < "abcd", "abc < abcd failed");
446 ok("abcd" < "abce", "abce < abce failed");
447 ok("" < "x", "\"\" < \"x\" failed");
448 ok(!(0 < 0), "0 < 0");
450 ok(1 <= 3.4, "1 <= 3.4 failed");
451 ok(!(3.4 <= 1), "3.4 <= 1");
452 ok("abc" <= "abcd", "abc <= abcd failed");
453 ok("abcd" <= "abce", "abce <= abce failed");
454 ok("" <= "x", "\"\" <= \"x\" failed");
455 ok(0 <= 0, "0 <= 0 failed");
457 ok(3.4 > 1, "3.4 > 1 failed");
458 ok(!(1 > 3.4), "1 > 3.4");
459 ok("abcd" > "abc", "abc > abcd failed");
460 ok("abce" > "abcd", "abce > abce failed");
461 ok("x" > "", "\"x\" > \"\" failed");
462 ok(!(0 > 0), "0 > 0");
464 ok(3.4 >= 1, "3.4 >= 1 failed");
465 ok(!(1 >= 3.4), "1 >= 3.4");
466 ok("abcd" >= "abc", "abc >= abcd failed");
467 ok("abce" >= "abcd", "abce >= abce failed");
468 ok("x" >= "", "\"x\" >= \"\" failed");
469 ok(0 >= 0, "0 >= 0");
471 tmp = 1;
472 ok(++tmp === 2, "++tmp (1) is not 2");
473 ok(tmp === 2, "incremented tmp is not 2");
474 ok(--tmp === 1, "--tmp (2) is not 1");
475 ok(tmp === 1, "decremented tmp is not 1");
476 ok(tmp++ === 1, "tmp++ (1) is not 1");
477 ok(tmp === 2, "incremented tmp(1) is not 2");
478 ok(tmp-- === 2, "tmp-- (2) is not 2");
479 ok(tmp === 1, "decremented tmp is not 1");
481 String.prototype.test = true;
482 ok("".test === true, "\"\".test is not true");
484 Boolean.prototype.test = true;
485 ok(true.test === true, "true.test is not true");
487 Number.prototype.test = true;
488 ok((0).test === true, "(0).test is not true");
489 ok((0.5).test === true, "(0.5).test is not true");
491 var state = "";
492 try {
493     ok(state === "", "try: state = " + state);
494     state = "try";
495 }catch(ex) {
496     ok(false, "unexpected catch");
498 ok(state === "try", "state = " + state + " expected try");
500 state = "";
501 try {
502     ok(state === "", "try: state = " + state);
503     state = "try";
504 }finally {
505     ok(state === "try", "finally: state = " + state);
506     state = "finally";
508 ok(state === "finally", "state = " + state + " expected finally");
510 state = "";
511 try {
512     ok(state === "", "try: state = " + state);
513     state = "try";
514 }catch(ex) {
515     ok(false, "unexpected catch");
516 }finally {
517     ok(state === "try", "finally: 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     throw "except";
527 }catch(ex) {
528     ok(state === "try", "catch: state = " + state);
529     ok(ex === "except", "ex is not \"except\"");
530     state = "catch";
532 ok(state === "catch", "state = " + state + " expected catch");
534 var state = "";
535 try {
536     ok(state === "", "try: state = " + state);
537     state = "try";
538     throw true;
539 }catch(ex) {
540     ok(state === "try", "catch: state = " + state);
541     ok(ex === true, "ex is not true");
542     state = "catch";
543 }finally {
544     ok(state === "catch", "finally: state = " + state);
545     state = "finally";
547 ok(state === "finally", "state = " + state + " expected finally");
549 var state = "";
550 try {
551     ok(state === "", "try: state = " + state);
552     state = "try";
553     try { throw true; } finally {}
554 }catch(ex) {
555     ok(state === "try", "catch: state = " + state);
556     ok(ex === true, "ex is not true");
557     state = "catch";
558 }finally {
559     ok(state === "catch", "finally: state = " + state);
560     state = "finally";
562 ok(state === "finally", "state = " + state + " expected finally");
564 var state = "";
565 try {
566     ok(state === "", "try: state = " + state);
567     state = "try";
568     try { throw "except"; } catch(ex) { throw true; }
569 }catch(ex) {
570     ok(state === "try", "catch: state = " + state);
571     ok(ex === true, "ex is not true");
572     state = "catch";
573 }finally {
574     ok(state === "catch", "finally: state = " + state);
575     state = "finally";
577 ok(state === "finally", "state = " + state + " expected finally");
579 function throwFunc(x) {
580     throw x;
583 var state = "";
584 try {
585     ok(state === "", "try: state = " + state);
586     state = "try";
587     throwFunc(true);
588 }catch(ex) {
589     ok(state === "try", "catch: state = " + state);
590     ok(ex === true, "ex is not true");
591     state = "catch";
592 }finally {
593     ok(state === "catch", "finally: state = " + state);
594     state = "finally";
596 ok(state === "finally", "state = " + state + " expected finally");
598 state = "";
599 switch(1) {
600 case "1":
601     ok(false, "unexpected case \"1\"");
602 case 1:
603     ok(state === "", "case 1: state = " + state);
604     state = "1";
605 default:
606     ok(state === "1", "default: state = " + state);
607     state = "default";
608 case false:
609     ok(state === "default", "case false: state = " + state);
610     state = "false";
612 ok(state === "false", "state = " + state);
614 state = "";
615 switch("") {
616 case "1":
617 case 1:
618     ok(false, "unexpected case 1");
619 default:
620     ok(state === "", "default: state = " + state);
621     state = "default";
622 case false:
623     ok(state === "default", "case false: state = " + state);
624     state = "false";
626 ok(state === "false", "state = " + state);
628 state = "";
629 switch(1) {
630 case "1":
631     ok(false, "unexpected case \"1\"");
632 case 1:
633     ok(state === "", "case 1: state = " + state);
634     state = "1";
635 default:
636     ok(state === "1", "default: state = " + state);
637     state = "default";
638     break;
639 case false:
640     ok(false, "unexpected case false");
642 ok(state === "default", "state = " + state);
644 tmp = eval("1");
645 ok(tmp === 1, "eval(\"1\") !== 1");
646 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
647 ok(tmp === 2, "tmp !== 2");
649 ok(eval(false) === false, "eval(false) !== false");
650 ok(eval() === undefined, "eval() !== undefined");
652 tmp = eval("1", "2");
653 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
655 var state = "";
656 try {
657     ok(state === "", "try: state = " + state);
658     state = "try";
659     eval("throwFunc(true);");
660 }catch(ex) {
661     ok(state === "try", "catch: state = " + state);
662     ok(ex === true, "ex is not true");
663     state = "catch";
664 }finally {
665     ok(state === "catch", "finally: state = " + state);
666     state = "finally";
668 ok(state === "finally", "state = " + state + " expected finally");
670 tmp = [,,1,2,,,true];
671 ok(tmp.length === 7, "tmp.length !== 7");
672 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
673 ok(tmp["3"] === 2, "tmp[3] !== 2");
674 ok(tmp["6"] === true, "tmp[6] !== true");
675 ok(tmp[2] === 1, "tmp[2] !== 1");
677 ok([1,].length === 2, "[1,].length !== 2");
678 ok([,,].length === 3, "[,,].length !== 3");
679 ok([,].length === 2, "[].length != 2");
680 ok([].length === 0, "[].length != 0");
682 tmp = 0;
683 while(tmp < 4) {
684     ok(tmp < 4, "tmp >= 4");
685     tmp++;
687 ok(tmp === 4, "tmp !== 4");
689 tmp = 0;
690 while(true) {
691     ok(tmp < 4, "tmp >= 4");
692     tmp++;
693     if(tmp === 4) {
694         break;
695         ok(false, "break did not break");
696     }
698 ok(tmp === 4, "tmp !== 4");
700 tmp = 0;
701 do {
702     ok(tmp < 4, "tmp >= 4");
703     tmp++;
704 } while(tmp < 4);
705 ok(tmp === 4, "tmp !== 4");
707 tmp = 0;
708 do {
709     ok(tmp === 0, "tmp !=== 0");
710     tmp++;
711 } while(false);
712 ok(tmp === 1, "tmp !== 1");
714 tmp = 0;
715 do {
716     ok(tmp < 4, "tmp >= 4");
717     tmp++;
718 } while(tmp < 4)
719 ok(tmp === 4, "tmp !== 4")
721 tmp = 0;
722 while(tmp < 4) {
723     tmp++;
724     if(tmp === 2) {
725         continue;
726         ok(false, "break did not break");
727     }
728     ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
730 ok(tmp === 4, "tmp !== 4");
732 for(tmp=0; tmp < 4; tmp++)
733     ok(tmp < 4, "tmp = " + tmp);
734 ok(tmp === 4, "tmp !== 4");
736 for(tmp=0; tmp < 4; tmp++) {
737     if(tmp === 2)
738         break;
739     ok(tmp < 2, "tmp = " + tmp);
741 ok(tmp === 2, "tmp !== 2");
743 for(tmp=0; tmp < 4; tmp++) {
744     if(tmp === 2)
745         continue;
746     ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
748 ok(tmp === 4, "tmp !== 4");
750 for(var fi=0; fi < 4; fi++)
751     ok(fi < 4, "fi = " + fi);
752 ok(fi === 4, "fi !== 4");
754 ok((void 1) === undefined, "(void 1) !== undefined");
756 var inobj = new Object();
758 for(var iter in inobj)
759     ok(false, "unexpected iter = " + iter);
761 inobj.test = true;
762 tmp = 0;
763 for(iter in inobj) {
764     ok(iter == "test", "unexpected iter = " + iter);
765     tmp++;
767 ok(tmp === 1, "for..in tmp = " + tmp);
769 function forinTestObj() {}
771 forinTestObj.prototype.test3 = true;
773 var arr = new Array();
774 inobj = new forinTestObj();
775 inobj.test1 = true;
776 inobj.test2 = true;
778 tmp = 0;
779 for(iter in inobj) {
780     arr[iter] = true;
781     tmp++;
784 ok(tmp === 3, "for..in tmp = " + tmp);
785 ok(arr["test1"] === true, "arr[test1] !== true");
786 ok(arr["test2"] === true, "arr[test2] !== true");
787 ok(arr["test3"] === true, "arr[test3] !== true");
789 tmp = new Object();
790 tmp.test = false;
791 ok((delete tmp.test) === true, "delete returned false");
792 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
793 for(iter in tmp)
794     ok(false, "tmp has prop " + iter);
796 tmp.testWith = true;
797 with(tmp)
798     ok(testWith === true, "testWith !== true");
800 if(false) {
801     var varTest1 = true;
804 ok(varTest1 === undefined, "varTest1 = " + varTest1);
805 ok(varTest2 === undefined, "varTest2 = " + varTest1);
807 var varTest2;
809 function varTestFunc(varTest3) {
810     var varTest3;
812     ok(varTest3 === 3, "varTest3 = " + varTest3);
813     ok(varTest4 === undefined, "varTest4 = " + varTest4);
815     var varTest4;
818 varTestFunc(3);
820 deleteTest = 1;
821 delete deleteTest;
822 try {
823     tmp = deleteTest;
824     ok(false, "deleteTest not throwed exception?");
825 }catch(ex) {}
827 if (false)
828     if (true)
829         ok(false, "if evaluated");
830     else
831         ok(false, "else should be associated with nearest if statement");
833 if (true)
834     if (false)
835         ok(false, "if evaluated");
836     else
837         ok(true, "else should be associated with nearest if statement");
839 function instanceOfTest() {}
840 tmp = new instanceOfTest();
842 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
843 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
844 ok((tmp instanceof String) === false, "tmp is instance of String");
846 instanceOfTest.prototype = new Object();
847 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
848 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
850 ok((1 instanceof Object) === false, "1 is instance of Object");
851 ok((false instanceof Boolean) === false, "false is instance of Boolean");
852 ok(("" instanceof Object) === false, "'' is instance of Object");
854 (function () {
855     ok((arguments instanceof Object) === true, "argument is not instance of Object");
856     ok((arguments instanceof Array) === false, "argument is not instance of Array");
857     ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
858 })(1,2);
860 obj = new String();
861 ok(("length" in obj) === true, "length is not in obj");
862 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
863 ok(("abc" in obj) === false, "test is in obj");
864 obj.abc = 1;
865 ok(("abc" in obj) === true, "test is not in obj");
866 ok(("1" in obj) === false, "1 is in obj");
868 obj = [1,2,3];
869 ok((1 in obj) === true, "1 is not in obj");
871 obj = new Object();
872 try {
873     obj.prop["test"];
874     ok(false, "expected exception");
875 }catch(e) {}
876 ok(!("prop" in obj), "prop in obj");
878 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
879 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
880 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
881 ok(isNaN() === true, "isNaN() !== true");
882 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
883 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
884 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
886 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
887 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
888 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
889 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
890 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
891 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
892 ok(isFinite() === false, "isFinite() !== false");
894 ok((1 < NaN) === false, "(1 < NaN) !== false");
895 ok((1 > NaN) === false, "(1 > NaN) !== false");
896 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
897 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
898 ok((NaN < 1) === false, "(NaN < 1) !== false");
899 ok((NaN > 1) === false, "(NaN > 1) !== false");
900 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
901 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
902 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
903 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
904 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
906 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
907 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
908 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
909 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
910 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
911 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
913 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
914 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
915 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
916 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
917 ok((0 === NaN) === false, "(0 === NaN) !== false");
919 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
920 ok((NaN == NaN) === false, "(NaN === NaN) != false");
921 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
922 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
923 ok((0 == NaN) === false, "(0 === NaN) != false");
926 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
927 tmp = testFunc2(1);
928 ok(tmp === 2, "testFunc2(1) = " + tmp);
929 function testFunc2(x) { return x+1; }
931 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
932 tmp = testFunc3(1);
933 ok(tmp === 3, "testFunc3(1) = " + tmp);
934 tmp = function testFunc3(x) { return x+2; };
936 tmp = testFunc4(1);
937 ok(tmp === 5, "testFunc4(1) = " + tmp);
938 tmp = function testFunc4(x) { return x+3; };
939 tmp = testFunc4(1);
940 testFunc4 = 1;
941 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
942 ok(tmp === 5, "testFunc4(1) = " + tmp);
943 tmp = function testFunc4(x) { return x+4; };
944 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
946 function testEmbededFunctions() {
947     ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
948     tmp = testFunc5(1);
949     ok(tmp === 3, "testFunc5(1) = " + tmp);
950     tmp = function testFunc5(x) { return x+2; };
952     tmp = testFunc6(1);
953     ok(tmp === 5, "testFunc6(1) = " + tmp);
954     tmp = function testFunc6(x) { return x+3; };
955     tmp = testFunc6(1);
956     ok(tmp === 5, "testFunc6(1) = " + tmp);
957     tmp = function testFunc6(x) { return x+4; };
958     testFunc6 = 1;
959     ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
962 testEmbededFunctions();
964 date = new Date();
965 date.toString = function() { return "toString"; }
966 ok(""+date === "toString", "''+date = " + date);
967 date.toString = function() { return this; }
968 ok(""+date === ""+date.valueOf(), "''+date = " + date);
970 str = new String("test");
971 str.valueOf = function() { return "valueOf"; }
972 ok(""+str === "valueOf", "''+str = " + str);
973 str.valueOf = function() { return new Date(); }
974 ok(""+str === "test", "''+str = " + str);
976 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
978 var re = /=(\?|%3F)/g;
979 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
981 tmp = new Array();
982 for(var i=0; i<2; i++)
983     tmp[i] = /b/;
984 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
986 ok(createNullBSTR() === '', "createNullBSTR() !== ''");
988 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
989 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
990 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
991 ok(nullDisp !== re, "nullDisp === re");
992 ok(nullDisp === null, "nullDisp === null");
993 ok(nullDisp == null, "nullDisp == null");
994 ok(getVT(true && nullDisp) === "VT_DISPATCH",
995    "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
996 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
997 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
998 ok(nullDisp != new Object(), "nullDisp == new Object()");
999 ok(new Object() != nullDisp, "new Object() == nullDisp");
1000 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1001 tmp = getVT(Object(nullDisp));
1002 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1003 tmp = Object(nullDisp).toString();
1004 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1006 function do_test() {}
1007 function nosemicolon() {} nosemicolon();
1008 function () {} nosemicolon();
1010 if(false) {
1011     function in_if_false() { return true; } ok(false, "!?");
1014 ok(in_if_false(), "in_if_false failed");
1016 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
1018 (function() { newValue = 1; })();
1019 ok(newValue === 1, "newValue = " + newValue);
1021 obj = {undefined: 3};
1023 /* Keep this test in the end of file */
1024 undefined = 6;
1025 ok(undefined === 6, "undefined = " + undefined);
1027 reportSuccess();