wer: Add new stubbed wer.dll.
[wine/hramrach.git] / dlls / jscript / tests / lang.js
blobbdf039a10219c7ad62d4d6e3137490fe7fe57d56
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
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");
72 ok(testFunc1.arguments === arguments, "testFunc1.arguments = " + testFunc1.arguments);
74 return true;
77 ok(testFunc1.length === 2, "testFunc1.length is not 2");
78 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
80 ok(Object.prototype !== undefined, "Object.prototype is undefined");
81 ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
82 ok(String.prototype !== undefined, "String.prototype is undefined");
83 ok(Array.prototype !== undefined, "Array.prototype is undefined");
84 ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
85 ok(Number.prototype !== undefined, "Number.prototype is undefined");
86 ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
87 ok(Math !== undefined, "Math is undefined");
88 ok(Math.prototype === undefined, "Math.prototype is not undefined");
89 ok(Function.prototype !== undefined, "Function.prototype is undefined");
90 ok(Function.prototype.prototype === undefined, "Function.prototype.prototype is not undefined");
91 ok(Date.prototype !== undefined, "Date.prototype is undefined");
92 ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
94 Function.prototype.test = true;
95 ok(testFunc1.test === true, "testFunc1.test !== true");
96 ok(Function.test === true, "Function.test !== true");
98 ok(typeof(0) === "number", "typeof(0) is not number");
99 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
100 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
101 ok(typeof("") === "string", "typeof(\"\") is not string");
102 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
103 ok(typeof(null) === "object", "typeof(null) is not object");
104 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
105 ok(typeof(Math) === "object", "typeof(Math) is not object");
106 ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
107 ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
108 ok(typeof(String) === "function", "typeof(String) is not function");
109 ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
110 ok(typeof(this) === "object", "typeof(this) is not object");
112 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
114 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
116 function testRecFunc(x) {
117 ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
118 if(x) {
119 testRecFunc(false);
120 ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
121 ok(testRecFunc.arguments[0] === true, "testRecFunc.arguments.x = " + testRecFunc.arguments[0]);
125 testRecFunc.arguments = 5;
126 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
127 testRecFunc(true);
128 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
130 tmp = (function() {1;})();
131 ok(tmp === undefined, "tmp = " + tmp);
132 tmp = eval("1;");
133 ok(tmp === 1, "tmp = " + tmp);
135 var obj1 = new Object();
136 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
137 ok(obj1.constructor === Object, "unexpected obj1.constructor");
138 obj1.test = true;
139 obj1.func = function () {
140 ok(this === obj1, "this is not obj1");
141 ok(this.test === true, "this.test is not true");
142 ok(arguments.length === 1, "arguments.length is not 1");
143 ok(arguments["0"] === true, "arguments[0] is not true");
144 ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
146 return "test";
149 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
151 function testConstr1() {
152 this.var1 = 1;
154 ok(this !== undefined, "this is undefined");
155 ok(arguments.length === 1, "arguments.length is not 1");
156 ok(arguments["0"] === true, "arguments[0] is not 1");
157 ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
159 return false;
162 testConstr1.prototype.pvar = 1;
164 var obj2 = new testConstr1(true);
165 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
166 ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
167 ok(obj2.pvar === 1, "obj2.pvar is not 1");
169 testConstr1.prototype.pvar = 2;
170 ok(obj2.pvar === 2, "obj2.pvar is not 2");
172 obj2.pvar = 3;
173 testConstr1.prototype.pvar = 1;
174 ok(obj2.pvar === 3, "obj2.pvar is not 3");
176 obj1 = new Object();
177 function testConstr3() {
178 return obj1;
181 obj2 = new testConstr3();
182 ok(obj1 === obj2, "obj1 != obj2");
184 function testConstr4() {
185 return 2;
188 obj2 = new testConstr3();
189 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
191 var obj3 = new Object;
192 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
194 for(var iter in "test")
195 ok(false, "unexpected forin call, test = " + iter);
197 for(var iter in null)
198 ok(false, "unexpected forin call, test = " + iter);
200 for(var iter in false)
201 ok(false, "unexpected forin call, test = " + iter);
203 tmp = 0;
204 if(true)
205 tmp = 1;
206 else
207 ok(false, "else evaluated");
208 ok(tmp === 1, "tmp !== 1, if not evaluated?");
210 tmp = 0;
211 if(1 === 0)
212 ok(false, "if evaluated");
213 else
214 tmp = 1;
215 ok(tmp === 1, "tmp !== 1, if not evaluated?");
217 if(false)
218 ok(false, "if(false) evaluated");
220 tmp = 0;
221 if(true)
222 tmp = 1;
223 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
225 if(false) {
226 }else {
229 var obj3 = { prop1: 1, prop2: typeof(false) };
230 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
231 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
232 ok(obj3.constructor === Object, "unexpected obj3.constructor");
235 var blockVar = 1;
236 blockVar = 2;
238 ok(blockVar === 2, "blockVar !== 2");
240 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
241 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
243 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
244 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
245 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
246 ok(getVT(0.5) === "VT_R8", "getVT(1.5) is not VT_R8");
247 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
248 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
249 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
251 tmp = 2+2;
252 ok(tmp === 4, "2+2 !== 4");
253 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
255 tmp = 2+2.5;
256 ok(tmp === 4.5, "2+2.5 !== 4.5");
257 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
259 tmp = 1.5+2.5;
260 ok(tmp === 4, "1.4+2.5 !== 4");
261 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
263 tmp = 4-2;
264 ok(tmp === 2, "4-2 !== 2");
265 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
267 tmp = 4.5-2;
268 ok(tmp === 2.5, "4.5-2 !== 2.5");
269 ok(getVT(tmp) === "VT_R8", "getVT(4-2) !== VT_R8");
271 tmp = -2;
272 ok(tmp === 0-2, "-2 !== 0-2");
273 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
275 tmp = 2*3;
276 ok(tmp === 6, "2*3 !== 6");
277 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
279 tmp = 2*3.5;
280 ok(tmp === 7, "2*3.5 !== 7");
281 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
283 tmp = 2.5*3.5;
284 /* FIXME: the parser loses precision */
285 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
286 ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
287 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
289 tmp = 4/2;
290 ok(tmp === 2, "4/2 !== 2");
291 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
293 tmp = 4.5/1.5;
294 ok(tmp === 3, "4.5/1.5 !== 3");
295 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
297 tmp = 3/2;
298 ok(tmp === 1.5, "3/2 !== 1.5");
299 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
301 tmp = 3%2;
302 ok(tmp === 1, "3%2 = " + tmp);
304 tmp = 4%2;
305 ok(tmp ===0, "4%2 = " + tmp);
307 tmp = 3.5%1.5;
308 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
310 tmp = 3%true;
311 ok(tmp === 0, "3%true = " + tmp);
313 tmp = "ab" + "cd";
314 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
316 tmp = 1;
317 ok((tmp += 1) === 2, "tmp += 1 !== 2");
318 ok(tmp === 2, "tmp !== 2");
320 tmp = 2;
321 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
322 ok(tmp === 1, "tmp !=== 1");
324 tmp = 2;
325 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
326 ok(tmp === 3, "tmp !=== 3");
328 tmp = 5;
329 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
330 ok(tmp === 2.5, "tmp !=== 2.5");
332 tmp = 3;
333 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
334 ok(tmp === 1, "tmp !== 1");
336 tmp = 8;
337 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
339 tmp = 8;
340 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
342 tmp = 8;
343 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
345 tmp = 3 || ok(false, "second or expression called");
346 ok(tmp === 3, "3 || (...) is not 3");
348 tmp = false || 2;
349 ok(tmp === 2, "false || 2 is not 2");
351 tmp = 0 && ok(false, "second and expression called");
352 ok(tmp === 0, "0 && (...) is not 0");
354 tmp = true && "test";
355 ok(tmp === "test", "true && \"test\" is not \"test\"");
357 tmp = true && 0;
358 ok(tmp === 0, "true && 0 is not 0");
360 tmp = 3 | 4;
361 ok(tmp === 7, "3 | 4 !== 7");
362 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
364 tmp = 3.5 | 0;
365 ok(tmp === 3, "3.5 | 0 !== 3");
366 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
368 tmp = -3.5 | 0;
369 ok(tmp === -3, "-3.5 | 0 !== -3");
370 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
372 tmp = 0 | NaN;
373 ok(tmp === 0, "0 | NaN = " + tmp);
375 tmp = 0 | Infinity;
376 ok(tmp === 0, "0 | NaN = " + tmp);
378 tmp = 0 | (-Infinity);
379 ok(tmp === 0, "0 | NaN = " + tmp);
381 tmp = 10;
382 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
383 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
385 tmp = 3 & 5;
386 ok(tmp === 1, "3 & 5 !== 1");
387 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
389 tmp = 3.5 & 0xffff;
390 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
391 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
393 tmp = (-3.5) & 0xffffffff;
394 ok(tmp === -3, "-3.5 & 0xffff !== -3");
395 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
397 tmp = 2 << 3;
398 ok(tmp === 16, "2 << 3 = " + tmp);
400 tmp = 2 << 35;
401 ok(tmp === 16, "2 << 35 = " + tmp);
403 tmp = 8 >> 2;
404 ok(tmp === 2, "8 >> 2 = " + tmp);
406 tmp = -64 >> 4;
407 ok(tmp === -4, "-64 >> 4 = " + tmp);
409 tmp = 8 >>> 2;
410 ok(tmp === 2, "8 >> 2 = " + tmp);
412 tmp = -64 >>> 4;
413 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
415 tmp = 4 >>> NaN;
416 ok(tmp === 4, "4 >>> NaN = " + tmp);
418 tmp = 10;
419 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
420 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
422 tmp = 0xf0f0^0xff00;
423 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
424 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
426 tmp = 5;
427 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
428 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
430 tmp = ~1;
431 ok(tmp === -2, "~1 !== -2");
432 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
434 ok((3,4) === 4, "(3,4) !== 4");
436 ok(+3 === 3, "+3 !== 3");
437 ok(+true === 1, "+true !== 1");
438 ok(+false === 0, "+false !== 0");
439 ok(+null === 0, "+null !== 0");
440 ok(+"0" === 0, "+'0' !== 0");
441 ok(+"3" === 3, "+'3' !== 3");
442 ok(+"-3" === -3, "+'-3' !== -3");
443 ok(+"0xff" === 255, "+'0xff' !== 255");
444 ok(+"3e3" === 3000, "+'3e3' !== 3000");
446 tmp = new Number(1);
447 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
448 ok(tmp.constructor === Number, "unexpected tmp.constructor");
449 tmp = new String("1");
450 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
451 ok(tmp.constructor === String, "unexpected tmp.constructor");
453 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
454 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
455 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
456 ok("" + null === "null", "\"\" + null !== \"null\"");
457 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
458 ok("" + true === "true", "\"\" + true !== \"true\"");
459 ok("" + false === "false", "\"\" + false !== \"false\"");
460 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
461 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
463 ok(1 < 3.4, "1 < 3.4 failed");
464 ok(!(3.4 < 1), "3.4 < 1");
465 ok("abc" < "abcd", "abc < abcd failed");
466 ok("abcd" < "abce", "abce < abce failed");
467 ok("" < "x", "\"\" < \"x\" failed");
468 ok(!(0 < 0), "0 < 0");
470 ok(1 <= 3.4, "1 <= 3.4 failed");
471 ok(!(3.4 <= 1), "3.4 <= 1");
472 ok("abc" <= "abcd", "abc <= abcd failed");
473 ok("abcd" <= "abce", "abce <= abce failed");
474 ok("" <= "x", "\"\" <= \"x\" failed");
475 ok(0 <= 0, "0 <= 0 failed");
477 ok(3.4 > 1, "3.4 > 1 failed");
478 ok(!(1 > 3.4), "1 > 3.4");
479 ok("abcd" > "abc", "abc > abcd failed");
480 ok("abce" > "abcd", "abce > abce failed");
481 ok("x" > "", "\"x\" > \"\" failed");
482 ok(!(0 > 0), "0 > 0");
484 ok(3.4 >= 1, "3.4 >= 1 failed");
485 ok(!(1 >= 3.4), "1 >= 3.4");
486 ok("abcd" >= "abc", "abc >= abcd failed");
487 ok("abce" >= "abcd", "abce >= abce failed");
488 ok("x" >= "", "\"x\" >= \"\" failed");
489 ok(0 >= 0, "0 >= 0");
491 tmp = 1;
492 ok(++tmp === 2, "++tmp (1) is not 2");
493 ok(tmp === 2, "incremented tmp is not 2");
494 ok(--tmp === 1, "--tmp (2) is not 1");
495 ok(tmp === 1, "decremented tmp is not 1");
496 ok(tmp++ === 1, "tmp++ (1) is not 1");
497 ok(tmp === 2, "incremented tmp(1) is not 2");
498 ok(tmp-- === 2, "tmp-- (2) is not 2");
499 ok(tmp === 1, "decremented tmp is not 1");
501 String.prototype.test = true;
502 ok("".test === true, "\"\".test is not true");
504 Boolean.prototype.test = true;
505 ok(true.test === true, "true.test is not true");
507 Number.prototype.test = true;
508 ok((0).test === true, "(0).test is not true");
509 ok((0.5).test === true, "(0.5).test is not true");
511 var state = "";
512 try {
513 ok(state === "", "try: state = " + state);
514 state = "try";
515 }catch(ex) {
516 ok(false, "unexpected catch");
518 ok(state === "try", "state = " + state + " expected try");
520 state = "";
521 try {
522 ok(state === "", "try: state = " + state);
523 state = "try";
524 }finally {
525 ok(state === "try", "finally: state = " + state);
526 state = "finally";
528 ok(state === "finally", "state = " + state + " expected finally");
530 state = "";
531 try {
532 ok(state === "", "try: state = " + state);
533 state = "try";
534 }catch(ex) {
535 ok(false, "unexpected catch");
536 }finally {
537 ok(state === "try", "finally: state = " + state);
538 state = "finally";
540 ok(state === "finally", "state = " + state + " expected finally");
542 var state = "";
543 try {
544 ok(state === "", "try: state = " + state);
545 state = "try";
546 throw "except";
547 }catch(ex) {
548 ok(state === "try", "catch: state = " + state);
549 ok(ex === "except", "ex is not \"except\"");
550 state = "catch";
552 ok(state === "catch", "state = " + state + " expected catch");
554 var state = "";
555 try {
556 ok(state === "", "try: state = " + state);
557 state = "try";
558 throw true;
559 }catch(ex) {
560 ok(state === "try", "catch: state = " + state);
561 ok(ex === true, "ex is not true");
562 state = "catch";
563 }finally {
564 ok(state === "catch", "finally: state = " + state);
565 state = "finally";
567 ok(state === "finally", "state = " + state + " expected finally");
569 var state = "";
570 try {
571 ok(state === "", "try: state = " + state);
572 state = "try";
573 try { throw true; } finally {}
574 }catch(ex) {
575 ok(state === "try", "catch: state = " + state);
576 ok(ex === true, "ex is not true");
577 state = "catch";
578 }finally {
579 ok(state === "catch", "finally: state = " + state);
580 state = "finally";
582 ok(state === "finally", "state = " + state + " expected finally");
584 var state = "";
585 try {
586 ok(state === "", "try: state = " + state);
587 state = "try";
588 try { throw "except"; } catch(ex) { throw true; }
589 }catch(ex) {
590 ok(state === "try", "catch: state = " + state);
591 ok(ex === true, "ex is not true");
592 state = "catch";
593 }finally {
594 ok(state === "catch", "finally: state = " + state);
595 state = "finally";
597 ok(state === "finally", "state = " + state + " expected finally");
599 function throwFunc(x) {
600 throw x;
603 var state = "";
604 try {
605 ok(state === "", "try: state = " + state);
606 state = "try";
607 throwFunc(true);
608 }catch(ex) {
609 ok(state === "try", "catch: state = " + state);
610 ok(ex === true, "ex is not true");
611 state = "catch";
612 }finally {
613 ok(state === "catch", "finally: state = " + state);
614 state = "finally";
616 ok(state === "finally", "state = " + state + " expected finally");
618 state = "";
619 switch(1) {
620 case "1":
621 ok(false, "unexpected case \"1\"");
622 case 1:
623 ok(state === "", "case 1: state = " + state);
624 state = "1";
625 default:
626 ok(state === "1", "default: state = " + state);
627 state = "default";
628 case false:
629 ok(state === "default", "case false: state = " + state);
630 state = "false";
632 ok(state === "false", "state = " + state);
634 state = "";
635 switch("") {
636 case "1":
637 case 1:
638 ok(false, "unexpected case 1");
639 default:
640 ok(state === "", "default: state = " + state);
641 state = "default";
642 case false:
643 ok(state === "default", "case false: state = " + state);
644 state = "false";
646 ok(state === "false", "state = " + state);
648 state = "";
649 switch(1) {
650 case "1":
651 ok(false, "unexpected case \"1\"");
652 case 1:
653 ok(state === "", "case 1: state = " + state);
654 state = "1";
655 default:
656 ok(state === "1", "default: state = " + state);
657 state = "default";
658 break;
659 case false:
660 ok(false, "unexpected case false");
662 ok(state === "default", "state = " + state);
664 tmp = eval("1");
665 ok(tmp === 1, "eval(\"1\") !== 1");
666 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
667 ok(tmp === 2, "tmp !== 2");
669 ok(eval(false) === false, "eval(false) !== false");
670 ok(eval() === undefined, "eval() !== undefined");
672 tmp = eval("1", "2");
673 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
675 var state = "";
676 try {
677 ok(state === "", "try: state = " + state);
678 state = "try";
679 eval("throwFunc(true);");
680 }catch(ex) {
681 ok(state === "try", "catch: state = " + state);
682 ok(ex === true, "ex is not true");
683 state = "catch";
684 }finally {
685 ok(state === "catch", "finally: state = " + state);
686 state = "finally";
688 ok(state === "finally", "state = " + state + " expected finally");
690 tmp = [,,1,2,,,true];
691 ok(tmp.length === 7, "tmp.length !== 7");
692 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
693 ok(tmp["3"] === 2, "tmp[3] !== 2");
694 ok(tmp["6"] === true, "tmp[6] !== true");
695 ok(tmp[2] === 1, "tmp[2] !== 1");
697 ok([1,].length === 2, "[1,].length !== 2");
698 ok([,,].length === 3, "[,,].length !== 3");
699 ok([,].length === 2, "[].length != 2");
700 ok([].length === 0, "[].length != 0");
702 tmp = 0;
703 while(tmp < 4) {
704 ok(tmp < 4, "tmp >= 4");
705 tmp++;
707 ok(tmp === 4, "tmp !== 4");
709 tmp = 0;
710 while(true) {
711 ok(tmp < 4, "tmp >= 4");
712 tmp++;
713 if(tmp === 4) {
714 break;
715 ok(false, "break did not break");
718 ok(tmp === 4, "tmp !== 4");
720 tmp = 0;
721 do {
722 ok(tmp < 4, "tmp >= 4");
723 tmp++;
724 } while(tmp < 4);
725 ok(tmp === 4, "tmp !== 4");
727 tmp = 0;
728 do {
729 ok(tmp === 0, "tmp !=== 0");
730 tmp++;
731 } while(false);
732 ok(tmp === 1, "tmp !== 1");
734 tmp = 0;
735 do {
736 ok(tmp < 4, "tmp >= 4");
737 tmp++;
738 } while(tmp < 4)
739 ok(tmp === 4, "tmp !== 4")
741 tmp = 0;
742 while(tmp < 4) {
743 tmp++;
744 if(tmp === 2) {
745 continue;
746 ok(false, "break did not break");
748 ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
750 ok(tmp === 4, "tmp !== 4");
752 for(tmp=0; tmp < 4; tmp++)
753 ok(tmp < 4, "tmp = " + tmp);
754 ok(tmp === 4, "tmp !== 4");
756 for(tmp=0; tmp < 4; tmp++) {
757 if(tmp === 2)
758 break;
759 ok(tmp < 2, "tmp = " + tmp);
761 ok(tmp === 2, "tmp !== 2");
763 for(tmp=0; tmp < 4; tmp++) {
764 if(tmp === 2)
765 continue;
766 ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
768 ok(tmp === 4, "tmp !== 4");
770 for(var fi=0; fi < 4; fi++)
771 ok(fi < 4, "fi = " + fi);
772 ok(fi === 4, "fi !== 4");
774 ok((void 1) === undefined, "(void 1) !== undefined");
776 var inobj = new Object();
778 for(var iter in inobj)
779 ok(false, "unexpected iter = " + iter);
781 inobj.test = true;
782 tmp = 0;
783 for(iter in inobj) {
784 ok(iter == "test", "unexpected iter = " + iter);
785 tmp++;
787 ok(tmp === 1, "for..in tmp = " + tmp);
789 function forinTestObj() {}
791 forinTestObj.prototype.test3 = true;
793 var arr = new Array();
794 inobj = new forinTestObj();
795 inobj.test1 = true;
796 inobj.test2 = true;
798 tmp = 0;
799 for(iter in inobj) {
800 arr[iter] = true;
801 tmp++;
804 ok(tmp === 3, "for..in tmp = " + tmp);
805 ok(arr["test1"] === true, "arr[test1] !== true");
806 ok(arr["test2"] === true, "arr[test2] !== true");
807 ok(arr["test3"] === true, "arr[test3] !== true");
809 tmp = new Object();
810 tmp.test = false;
811 ok((delete tmp.test) === true, "delete returned false");
812 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
813 for(iter in tmp)
814 ok(false, "tmp has prop " + iter);
816 tmp.testWith = true;
817 with(tmp)
818 ok(testWith === true, "testWith !== true");
820 if(false) {
821 var varTest1 = true;
824 ok(varTest1 === undefined, "varTest1 = " + varTest1);
825 ok(varTest2 === undefined, "varTest2 = " + varTest1);
827 var varTest2;
829 function varTestFunc(varTest3) {
830 var varTest3;
832 ok(varTest3 === 3, "varTest3 = " + varTest3);
833 ok(varTest4 === undefined, "varTest4 = " + varTest4);
835 var varTest4;
838 varTestFunc(3);
840 deleteTest = 1;
841 delete deleteTest;
842 try {
843 tmp = deleteTest;
844 ok(false, "deleteTest not throwed exception?");
845 }catch(ex) {}
847 if (false)
848 if (true)
849 ok(false, "if evaluated");
850 else
851 ok(false, "else should be associated with nearest if statement");
853 if (true)
854 if (false)
855 ok(false, "if evaluated");
856 else
857 ok(true, "else should be associated with nearest if statement");
859 function instanceOfTest() {}
860 tmp = new instanceOfTest();
862 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
863 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
864 ok((tmp instanceof String) === false, "tmp is instance of String");
866 instanceOfTest.prototype = new Object();
867 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
868 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
870 ok((1 instanceof Object) === false, "1 is instance of Object");
871 ok((false instanceof Boolean) === false, "false is instance of Boolean");
872 ok(("" instanceof Object) === false, "'' is instance of Object");
874 (function () {
875 ok((arguments instanceof Object) === true, "argument is not instance of Object");
876 ok((arguments instanceof Array) === false, "argument is not instance of Array");
877 ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
878 })(1,2);
880 obj = new String();
881 ok(("length" in obj) === true, "length is not in obj");
882 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
883 ok(("abc" in obj) === false, "test is in obj");
884 obj.abc = 1;
885 ok(("abc" in obj) === true, "test is not in obj");
886 ok(("1" in obj) === false, "1 is in obj");
888 obj = [1,2,3];
889 ok((1 in obj) === true, "1 is not in obj");
891 obj = new Object();
892 try {
893 obj.prop["test"];
894 ok(false, "expected exception");
895 }catch(e) {}
896 ok(!("prop" in obj), "prop in obj");
898 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
899 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
900 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
901 ok(isNaN() === true, "isNaN() !== true");
902 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
903 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
904 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
906 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
907 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
908 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
909 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
910 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
911 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
912 ok(isFinite() === false, "isFinite() !== false");
914 ok((1 < NaN) === false, "(1 < NaN) !== false");
915 ok((1 > NaN) === false, "(1 > NaN) !== false");
916 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
917 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
918 ok((NaN < 1) === false, "(NaN < 1) !== false");
919 ok((NaN > 1) === false, "(NaN > 1) !== false");
920 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
921 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
922 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
923 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
924 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
926 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
927 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
928 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
929 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
930 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
931 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
933 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
934 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
935 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
936 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
937 ok((0 === NaN) === false, "(0 === NaN) !== false");
939 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
940 ok((NaN == NaN) === false, "(NaN === NaN) != false");
941 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
942 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
943 ok((0 == NaN) === false, "(0 === NaN) != false");
946 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
947 tmp = testFunc2(1);
948 ok(tmp === 2, "testFunc2(1) = " + tmp);
949 function testFunc2(x) { return x+1; }
951 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
952 tmp = testFunc3(1);
953 ok(tmp === 3, "testFunc3(1) = " + tmp);
954 tmp = function testFunc3(x) { return x+2; };
956 tmp = testFunc4(1);
957 ok(tmp === 5, "testFunc4(1) = " + tmp);
958 tmp = function testFunc4(x) { return x+3; };
959 tmp = testFunc4(1);
960 testFunc4 = 1;
961 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
962 ok(tmp === 5, "testFunc4(1) = " + tmp);
963 tmp = function testFunc4(x) { return x+4; };
964 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
966 function testEmbededFunctions() {
967 ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
968 tmp = testFunc5(1);
969 ok(tmp === 3, "testFunc5(1) = " + tmp);
970 tmp = function testFunc5(x) { return x+2; };
972 tmp = testFunc6(1);
973 ok(tmp === 5, "testFunc6(1) = " + tmp);
974 tmp = function testFunc6(x) { return x+3; };
975 tmp = testFunc6(1);
976 ok(tmp === 5, "testFunc6(1) = " + tmp);
977 tmp = function testFunc6(x) { return x+4; };
978 testFunc6 = 1;
979 ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
982 testEmbededFunctions();
984 date = new Date();
985 date.toString = function() { return "toString"; }
986 ok(""+date === "toString", "''+date = " + date);
987 date.toString = function() { return this; }
988 ok(""+date === ""+date.valueOf(), "''+date = " + date);
990 str = new String("test");
991 str.valueOf = function() { return "valueOf"; }
992 ok(""+str === "valueOf", "''+str = " + str);
993 str.valueOf = function() { return new Date(); }
994 ok(""+str === "test", "''+str = " + str);
996 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
998 var re = /=(\?|%3F)/g;
999 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
1001 tmp = new Array();
1002 for(var i=0; i<2; i++)
1003 tmp[i] = /b/;
1004 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
1006 ok(createNullBSTR() === '', "createNullBSTR() !== ''");
1008 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1009 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1010 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
1011 ok(nullDisp !== re, "nullDisp === re");
1012 ok(nullDisp === null, "nullDisp === null");
1013 ok(nullDisp == null, "nullDisp == null");
1014 ok(getVT(true && nullDisp) === "VT_DISPATCH",
1015 "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
1016 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1017 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1018 ok(nullDisp != new Object(), "nullDisp == new Object()");
1019 ok(new Object() != nullDisp, "new Object() == nullDisp");
1020 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1021 tmp = getVT(Object(nullDisp));
1022 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1023 tmp = Object(nullDisp).toString();
1024 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1026 function do_test() {}
1027 function nosemicolon() {} nosemicolon();
1028 function () {} nosemicolon();
1030 if(false) {
1031 function in_if_false() { return true; } ok(false, "!?");
1034 ok(in_if_false(), "in_if_false failed");
1036 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
1038 (function() { newValue = 1; })();
1039 ok(newValue === 1, "newValue = " + newValue);
1041 obj = {undefined: 3};
1043 /* Keep this test in the end of file */
1044 undefined = 6;
1045 ok(undefined === 6, "undefined = " + undefined);
1047 NaN = 6;
1048 ok(NaN === 6, "NaN !== 6");
1050 Infinity = 6;
1051 ok(Infinity === 6, "Infinity !== 6");
1053 Math = 6;
1054 ok(Math === 6, "NaN !== 6");
1056 reportSuccess();