user32: Add separate sysmenu for MDI child windows.
[wine] / dlls / jscript / tests / lang.js
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  */
18
19 var tmp;
20
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");
27
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");
40
41 ok(1 !== 2, "1 !== 2 is false");
42 ok(null !== undefined, "null !== undefined is false");
43
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");
55
56 ok(1 != 2, "1 != 2 is false");
57 ok(false != 1, "false != 1 is false");
58
59 var trueVar = true;
60 ok(trueVar, "trueVar is not true");
61
62 ok(ScriptEngine.length === 0, "ScriptEngine.length is not 0");
63
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);
73
74     return true;
75 }
76
77 ok(testFunc1.length === 2, "testFunc1.length is not 2");
78 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
79
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");
93
94 Function.prototype.test = true;
95 ok(testFunc1.test === true, "testFunc1.test !== true");
96 ok(Function.test === true, "Function.test !== true");
97
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");
111 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
112 tmp = typeof((new Object()).doesnotexist);
113 ok(tmp === "undefined", "typeof((new Object).doesnotexist = " + tmp);
114 tmp = typeof(testObj.onlyDispID);
115 ok(tmp === "unknown", "typeof(testObj.onlyDispID) = " + tmp);
116
117 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
118
119 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
120
121 function testRecFunc(x) {
122     ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
123     if(x) {
124         testRecFunc(false);
125         ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
126         ok(testRecFunc.arguments[0] === true, "testRecFunc.arguments.x = " + testRecFunc.arguments[0]);
127     }
128 }
129
130 testRecFunc.arguments = 5;
131 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
132 testRecFunc(true);
133 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
134
135 tmp = (function() {1;})();
136 ok(tmp === undefined, "tmp = " + tmp);
137 tmp = eval("1;");
138 ok(tmp === 1, "tmp = " + tmp);
139
140 var obj1 = new Object();
141 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
142 ok(obj1.constructor === Object, "unexpected obj1.constructor");
143 obj1.test = true;
144 obj1.func = function () {
145     ok(this === obj1, "this is not obj1");
146     ok(this.test === true, "this.test is not true");
147     ok(arguments.length === 1, "arguments.length is not 1");
148     ok(arguments["0"] === true, "arguments[0] is not true");
149     ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
150
151     return "test";
152 };
153
154 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
155
156 function testConstr1() {
157     this.var1 = 1;
158
159     ok(this !== undefined, "this is undefined");
160     ok(arguments.length === 1, "arguments.length is not 1");
161     ok(arguments["0"] === true, "arguments[0] is not 1");
162     ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
163
164     return false;
165 }
166
167 testConstr1.prototype.pvar = 1;
168
169 var obj2 = new testConstr1(true);
170 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
171 ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
172 ok(obj2.pvar === 1, "obj2.pvar is not 1");
173
174 testConstr1.prototype.pvar = 2;
175 ok(obj2.pvar === 2, "obj2.pvar is not 2");
176
177 obj2.pvar = 3;
178 testConstr1.prototype.pvar = 1;
179 ok(obj2.pvar === 3, "obj2.pvar is not 3");
180
181 obj1 = new Object();
182 function testConstr3() {
183     return obj1;
184 }
185
186 obj2 = new testConstr3();
187 ok(obj1 === obj2, "obj1 != obj2");
188
189 function testConstr4() {
190     return 2;
191 }
192
193 obj2 = new testConstr3();
194 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
195
196 var obj3 = new Object;
197 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
198
199 for(var iter in "test")
200     ok(false, "unexpected forin call, test = " + iter);
201
202 for(var iter in null)
203     ok(false, "unexpected forin call, test = " + iter);
204
205 for(var iter in false)
206     ok(false, "unexpected forin call, test = " + iter);
207
208 tmp = 0;
209 if(true)
210     tmp = 1;
211 else
212     ok(false, "else evaluated");
213 ok(tmp === 1, "tmp !== 1, if not evaluated?");
214
215 tmp = 0;
216 if(1 === 0)
217     ok(false, "if evaluated");
218 else
219     tmp = 1;
220 ok(tmp === 1, "tmp !== 1, if not evaluated?");
221
222 if(false)
223     ok(false, "if(false) evaluated");
224
225 tmp = 0;
226 if(true)
227     tmp = 1;
228 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
229
230 if(false) {
231 }else {
232 }
233
234 var obj3 = { prop1: 1,  prop2: typeof(false) };
235 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
236 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
237 ok(obj3.constructor === Object, "unexpected obj3.constructor");
238
239 {
240     var blockVar = 1;
241     blockVar = 2;
242 }
243 ok(blockVar === 2, "blockVar !== 2");
244
245 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
246 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
247
248 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
249 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
250 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
251 ok(getVT(0.5) === "VT_R8", "getVT(1.5) is not VT_R8");
252 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
253 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
254 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
255
256 tmp = 2+2;
257 ok(tmp === 4, "2+2 !== 4");
258 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
259
260 tmp = 2+2.5;
261 ok(tmp === 4.5, "2+2.5 !== 4.5");
262 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
263
264 tmp = 1.5+2.5;
265 ok(tmp === 4, "1.4+2.5 !== 4");
266 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
267
268 tmp = 4-2;
269 ok(tmp === 2, "4-2 !== 2");
270 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
271
272 tmp = 4.5-2;
273 ok(tmp === 2.5, "4.5-2 !== 2.5");
274 ok(getVT(tmp) === "VT_R8", "getVT(4-2) !== VT_R8");
275
276 tmp = -2;
277 ok(tmp === 0-2, "-2 !== 0-2");
278 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
279
280 tmp = 2*3;
281 ok(tmp === 6, "2*3 !== 6");
282 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
283
284 tmp = 2*3.5;
285 ok(tmp === 7, "2*3.5 !== 7");
286 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
287
288 tmp = 2.5*3.5;
289 /* FIXME: the parser loses precision */
290 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
291 ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
292 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
293
294 tmp = 4/2;
295 ok(tmp === 2, "4/2 !== 2");
296 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
297
298 tmp = 4.5/1.5;
299 ok(tmp === 3, "4.5/1.5 !== 3");
300 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
301
302 tmp = 3/2;
303 ok(tmp === 1.5, "3/2 !== 1.5");
304 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
305
306 tmp = 3%2;
307 ok(tmp === 1, "3%2 = " + tmp);
308
309 tmp = 4%2;
310 ok(tmp ===0, "4%2 = " + tmp);
311
312 tmp = 3.5%1.5;
313 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
314
315 tmp = 3%true;
316 ok(tmp === 0, "3%true = " + tmp);
317
318 tmp = "ab" + "cd";
319 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
320
321 tmp = 1;
322 ok((tmp += 1) === 2, "tmp += 1 !== 2");
323 ok(tmp === 2, "tmp !== 2");
324
325 tmp = 2;
326 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
327 ok(tmp === 1, "tmp !=== 1");
328
329 tmp = 2;
330 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
331 ok(tmp === 3, "tmp !=== 3");
332
333 tmp = 5;
334 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
335 ok(tmp === 2.5, "tmp !=== 2.5");
336
337 tmp = 3;
338 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
339 ok(tmp === 1, "tmp !== 1");
340
341 tmp = 8;
342 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
343
344 tmp = 8;
345 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
346
347 tmp = 8;
348 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
349
350 tmp = 3 || ok(false, "second or expression called");
351 ok(tmp === 3, "3 || (...) is not 3");
352
353 tmp = false || 2;
354 ok(tmp === 2, "false || 2 is not 2");
355
356 tmp = 0 && ok(false, "second and expression called");
357 ok(tmp === 0, "0 && (...) is not 0");
358
359 tmp = true && "test";
360 ok(tmp === "test", "true && \"test\" is not \"test\"");
361
362 tmp = true && 0;
363 ok(tmp === 0, "true && 0 is not 0");
364
365 tmp = 3 | 4;
366 ok(tmp === 7, "3 | 4 !== 7");
367 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
368
369 tmp = 3.5 | 0;
370 ok(tmp === 3, "3.5 | 0 !== 3");
371 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
372
373 tmp = -3.5 | 0;
374 ok(tmp === -3, "-3.5 | 0 !== -3");
375 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
376
377 tmp = 0 | NaN;
378 ok(tmp === 0, "0 | NaN = " + tmp);
379
380 tmp = 0 | Infinity;
381 ok(tmp === 0, "0 | NaN = " + tmp);
382
383 tmp = 0 | (-Infinity);
384 ok(tmp === 0, "0 | NaN = " + tmp);
385
386 tmp = 10;
387 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
388 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
389
390 tmp = 3 & 5;
391 ok(tmp === 1, "3 & 5 !== 1");
392 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
393
394 tmp = 3.5 & 0xffff;
395 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
396 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
397
398 tmp = (-3.5) & 0xffffffff;
399 ok(tmp === -3, "-3.5 & 0xffff !== -3");
400 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
401
402 tmp = 2 << 3;
403 ok(tmp === 16, "2 << 3 = " + tmp);
404
405 tmp = 2 << 35;
406 ok(tmp === 16, "2 << 35 = " + tmp);
407
408 tmp = 8 >> 2;
409 ok(tmp === 2, "8 >> 2 = " + tmp);
410
411 tmp = -64 >> 4;
412 ok(tmp === -4, "-64 >> 4 = " + tmp);
413
414 tmp = 8 >>> 2;
415 ok(tmp === 2, "8 >> 2 = " + tmp);
416
417 tmp = -64 >>> 4;
418 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
419
420 tmp = 4 >>> NaN;
421 ok(tmp === 4, "4 >>> NaN = " + tmp);
422
423 tmp = 10;
424 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
425 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
426
427 tmp = 0xf0f0^0xff00;
428 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
429 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
430
431 tmp = 5;
432 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
433 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
434
435 tmp = ~1;
436 ok(tmp === -2, "~1 !== -2");
437 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
438
439 ok((3,4) === 4, "(3,4) !== 4");
440
441 ok(+3 === 3, "+3 !== 3");
442 ok(+true === 1, "+true !== 1");
443 ok(+false === 0, "+false !== 0");
444 ok(+null === 0, "+null !== 0");
445 ok(+"0" === 0, "+'0' !== 0");
446 ok(+"3" === 3, "+'3' !== 3");
447 ok(+"-3" === -3, "+'-3' !== -3");
448 ok(+"0xff" === 255, "+'0xff' !== 255");
449 ok(+"3e3" === 3000, "+'3e3' !== 3000");
450
451 tmp = new Number(1);
452 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
453 ok(tmp.constructor === Number, "unexpected tmp.constructor");
454 tmp = new String("1");
455 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
456 ok(tmp.constructor === String, "unexpected tmp.constructor");
457
458 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
459 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
460 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
461 ok("" + null === "null", "\"\" + null !== \"null\"");
462 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
463 ok("" + true === "true", "\"\" + true !== \"true\"");
464 ok("" + false === "false", "\"\" + false !== \"false\"");
465 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
466 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
467
468 ok(1 < 3.4, "1 < 3.4 failed");
469 ok(!(3.4 < 1), "3.4 < 1");
470 ok("abc" < "abcd", "abc < abcd failed");
471 ok("abcd" < "abce", "abce < abce failed");
472 ok("" < "x", "\"\" < \"x\" failed");
473 ok(!(0 < 0), "0 < 0");
474
475 ok(1 <= 3.4, "1 <= 3.4 failed");
476 ok(!(3.4 <= 1), "3.4 <= 1");
477 ok("abc" <= "abcd", "abc <= abcd failed");
478 ok("abcd" <= "abce", "abce <= abce failed");
479 ok("" <= "x", "\"\" <= \"x\" failed");
480 ok(0 <= 0, "0 <= 0 failed");
481
482 ok(3.4 > 1, "3.4 > 1 failed");
483 ok(!(1 > 3.4), "1 > 3.4");
484 ok("abcd" > "abc", "abc > abcd failed");
485 ok("abce" > "abcd", "abce > abce failed");
486 ok("x" > "", "\"x\" > \"\" failed");
487 ok(!(0 > 0), "0 > 0");
488
489 ok(3.4 >= 1, "3.4 >= 1 failed");
490 ok(!(1 >= 3.4), "1 >= 3.4");
491 ok("abcd" >= "abc", "abc >= abcd failed");
492 ok("abce" >= "abcd", "abce >= abce failed");
493 ok("x" >= "", "\"x\" >= \"\" failed");
494 ok(0 >= 0, "0 >= 0");
495
496 tmp = 1;
497 ok(++tmp === 2, "++tmp (1) is not 2");
498 ok(tmp === 2, "incremented tmp is not 2");
499 ok(--tmp === 1, "--tmp (2) is not 1");
500 ok(tmp === 1, "decremented tmp is not 1");
501 ok(tmp++ === 1, "tmp++ (1) is not 1");
502 ok(tmp === 2, "incremented tmp(1) is not 2");
503 ok(tmp-- === 2, "tmp-- (2) is not 2");
504 ok(tmp === 1, "decremented tmp is not 1");
505
506 String.prototype.test = true;
507 ok("".test === true, "\"\".test is not true");
508
509 Boolean.prototype.test = true;
510 ok(true.test === true, "true.test is not true");
511
512 Number.prototype.test = true;
513 ok((0).test === true, "(0).test is not true");
514 ok((0.5).test === true, "(0.5).test is not true");
515
516 var state = "";
517 try {
518     ok(state === "", "try: state = " + state);
519     state = "try";
520 }catch(ex) {
521     ok(false, "unexpected catch");
522 }
523 ok(state === "try", "state = " + state + " expected try");
524
525 state = "";
526 try {
527     ok(state === "", "try: state = " + state);
528     state = "try";
529 }finally {
530     ok(state === "try", "finally: state = " + state);
531     state = "finally";
532 }
533 ok(state === "finally", "state = " + state + " expected finally");
534
535 state = "";
536 try {
537     ok(state === "", "try: state = " + state);
538     state = "try";
539 }catch(ex) {
540     ok(false, "unexpected catch");
541 }finally {
542     ok(state === "try", "finally: state = " + state);
543     state = "finally";
544 }
545 ok(state === "finally", "state = " + state + " expected finally");
546
547 var state = "";
548 try {
549     ok(state === "", "try: state = " + state);
550     state = "try";
551     throw "except";
552 }catch(ex) {
553     ok(state === "try", "catch: state = " + state);
554     ok(ex === "except", "ex is not \"except\"");
555     state = "catch";
556 }
557 ok(state === "catch", "state = " + state + " expected catch");
558
559 var state = "";
560 try {
561     ok(state === "", "try: state = " + state);
562     state = "try";
563     throw true;
564 }catch(ex) {
565     ok(state === "try", "catch: state = " + state);
566     ok(ex === true, "ex is not true");
567     state = "catch";
568 }finally {
569     ok(state === "catch", "finally: state = " + state);
570     state = "finally";
571 }
572 ok(state === "finally", "state = " + state + " expected finally");
573
574 var state = "";
575 try {
576     ok(state === "", "try: state = " + state);
577     state = "try";
578     try { throw true; } finally {}
579 }catch(ex) {
580     ok(state === "try", "catch: state = " + state);
581     ok(ex === true, "ex is not true");
582     state = "catch";
583 }finally {
584     ok(state === "catch", "finally: state = " + state);
585     state = "finally";
586 }
587 ok(state === "finally", "state = " + state + " expected finally");
588
589 var state = "";
590 try {
591     ok(state === "", "try: state = " + state);
592     state = "try";
593     try { throw "except"; } catch(ex) { throw true; }
594 }catch(ex) {
595     ok(state === "try", "catch: state = " + state);
596     ok(ex === true, "ex is not true");
597     state = "catch";
598 }finally {
599     ok(state === "catch", "finally: state = " + state);
600     state = "finally";
601 }
602 ok(state === "finally", "state = " + state + " expected finally");
603
604 function throwFunc(x) {
605     throw x;
606 }
607
608 var state = "";
609 try {
610     ok(state === "", "try: state = " + state);
611     state = "try";
612     throwFunc(true);
613 }catch(ex) {
614     ok(state === "try", "catch: state = " + state);
615     ok(ex === true, "ex is not true");
616     state = "catch";
617 }finally {
618     ok(state === "catch", "finally: state = " + state);
619     state = "finally";
620 }
621 ok(state === "finally", "state = " + state + " expected finally");
622
623 state = "";
624 switch(1) {
625 case "1":
626     ok(false, "unexpected case \"1\"");
627 case 1:
628     ok(state === "", "case 1: state = " + state);
629     state = "1";
630 default:
631     ok(state === "1", "default: state = " + state);
632     state = "default";
633 case false:
634     ok(state === "default", "case false: state = " + state);
635     state = "false";
636 }
637 ok(state === "false", "state = " + state);
638
639 state = "";
640 switch("") {
641 case "1":
642 case 1:
643     ok(false, "unexpected case 1");
644 default:
645     ok(state === "", "default: state = " + state);
646     state = "default";
647 case false:
648     ok(state === "default", "case false: state = " + state);
649     state = "false";
650 }
651 ok(state === "false", "state = " + state);
652
653 state = "";
654 switch(1) {
655 case "1":
656     ok(false, "unexpected case \"1\"");
657 case 1:
658     ok(state === "", "case 1: state = " + state);
659     state = "1";
660 default:
661     ok(state === "1", "default: state = " + state);
662     state = "default";
663     break;
664 case false:
665     ok(false, "unexpected case false");
666 }
667 ok(state === "default", "state = " + state);
668
669 tmp = eval("1");
670 ok(tmp === 1, "eval(\"1\") !== 1");
671 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
672 ok(tmp === 2, "tmp !== 2");
673
674 ok(eval(false) === false, "eval(false) !== false");
675 ok(eval() === undefined, "eval() !== undefined");
676
677 tmp = eval("1", "2");
678 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
679
680 var state = "";
681 try {
682     ok(state === "", "try: state = " + state);
683     state = "try";
684     eval("throwFunc(true);");
685 }catch(ex) {
686     ok(state === "try", "catch: state = " + state);
687     ok(ex === true, "ex is not true");
688     state = "catch";
689 }finally {
690     ok(state === "catch", "finally: state = " + state);
691     state = "finally";
692 }
693 ok(state === "finally", "state = " + state + " expected finally");
694
695 tmp = [,,1,2,,,true];
696 ok(tmp.length === 7, "tmp.length !== 7");
697 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
698 ok(tmp["3"] === 2, "tmp[3] !== 2");
699 ok(tmp["6"] === true, "tmp[6] !== true");
700 ok(tmp[2] === 1, "tmp[2] !== 1");
701
702 ok([1,].length === 2, "[1,].length !== 2");
703 ok([,,].length === 3, "[,,].length !== 3");
704 ok([,].length === 2, "[].length != 2");
705 ok([].length === 0, "[].length != 0");
706
707 tmp = 0;
708 while(tmp < 4) {
709     ok(tmp < 4, "tmp >= 4");
710     tmp++;
711 }
712 ok(tmp === 4, "tmp !== 4");
713
714 tmp = 0;
715 while(true) {
716     ok(tmp < 4, "tmp >= 4");
717     tmp++;
718     if(tmp === 4) {
719         break;
720         ok(false, "break did not break");
721     }
722 }
723 ok(tmp === 4, "tmp !== 4");
724
725 tmp = 0;
726 do {
727     ok(tmp < 4, "tmp >= 4");
728     tmp++;
729 } while(tmp < 4);
730 ok(tmp === 4, "tmp !== 4");
731
732 tmp = 0;
733 do {
734     ok(tmp === 0, "tmp !=== 0");
735     tmp++;
736 } while(false);
737 ok(tmp === 1, "tmp !== 1");
738
739 tmp = 0;
740 do {
741     ok(tmp < 4, "tmp >= 4");
742     tmp++;
743 } while(tmp < 4)
744 ok(tmp === 4, "tmp !== 4")
745
746 tmp = 0;
747 while(tmp < 4) {
748     tmp++;
749     if(tmp === 2) {
750         continue;
751         ok(false, "break did not break");
752     }
753     ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
754 }
755 ok(tmp === 4, "tmp !== 4");
756
757 for(tmp=0; tmp < 4; tmp++)
758     ok(tmp < 4, "tmp = " + tmp);
759 ok(tmp === 4, "tmp !== 4");
760
761 for(tmp=0; tmp < 4; tmp++) {
762     if(tmp === 2)
763         break;
764     ok(tmp < 2, "tmp = " + tmp);
765 }
766 ok(tmp === 2, "tmp !== 2");
767
768 for(tmp=0; tmp < 4; tmp++) {
769     if(tmp === 2)
770         continue;
771     ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
772 }
773 ok(tmp === 4, "tmp !== 4");
774
775 for(var fi=0; fi < 4; fi++)
776     ok(fi < 4, "fi = " + fi);
777 ok(fi === 4, "fi !== 4");
778
779 ok((void 1) === undefined, "(void 1) !== undefined");
780
781 var inobj = new Object();
782
783 for(var iter in inobj)
784     ok(false, "unexpected iter = " + iter);
785
786 inobj.test = true;
787 tmp = 0;
788 for(iter in inobj) {
789     ok(iter == "test", "unexpected iter = " + iter);
790     tmp++;
791 }
792 ok(tmp === 1, "for..in tmp = " + tmp);
793
794 function forinTestObj() {}
795
796 forinTestObj.prototype.test3 = true;
797
798 var arr = new Array();
799 inobj = new forinTestObj();
800 inobj.test1 = true;
801 inobj.test2 = true;
802
803 tmp = 0;
804 for(iter in inobj) {
805     arr[iter] = true;
806     tmp++;
807 }
808
809 ok(tmp === 3, "for..in tmp = " + tmp);
810 ok(arr["test1"] === true, "arr[test1] !== true");
811 ok(arr["test2"] === true, "arr[test2] !== true");
812 ok(arr["test3"] === true, "arr[test3] !== true");
813
814 tmp = new Object();
815 tmp.test = false;
816 ok((delete tmp.test) === true, "delete returned false");
817 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
818 for(iter in tmp)
819     ok(false, "tmp has prop " + iter);
820
821 tmp.testWith = true;
822 with(tmp)
823     ok(testWith === true, "testWith !== true");
824
825 if(false) {
826     var varTest1 = true;
827 }
828
829 ok(varTest1 === undefined, "varTest1 = " + varTest1);
830 ok(varTest2 === undefined, "varTest2 = " + varTest1);
831
832 var varTest2;
833
834 function varTestFunc(varTest3) {
835     var varTest3;
836
837     ok(varTest3 === 3, "varTest3 = " + varTest3);
838     ok(varTest4 === undefined, "varTest4 = " + varTest4);
839
840     var varTest4;
841 }
842
843 varTestFunc(3);
844
845 deleteTest = 1;
846 delete deleteTest;
847 try {
848     tmp = deleteTest;
849     ok(false, "deleteTest not throwed exception?");
850 }catch(ex) {}
851
852 if (false)
853     if (true)
854         ok(false, "if evaluated");
855     else
856         ok(false, "else should be associated with nearest if statement");
857
858 if (true)
859     if (false)
860         ok(false, "if evaluated");
861     else
862         ok(true, "else should be associated with nearest if statement");
863
864 function instanceOfTest() {}
865 tmp = new instanceOfTest();
866
867 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
868 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
869 ok((tmp instanceof String) === false, "tmp is instance of String");
870
871 instanceOfTest.prototype = new Object();
872 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
873 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
874
875 ok((1 instanceof Object) === false, "1 is instance of Object");
876 ok((false instanceof Boolean) === false, "false is instance of Boolean");
877 ok(("" instanceof Object) === false, "'' is instance of Object");
878
879 (function () {
880     ok((arguments instanceof Object) === true, "argument is not instance of Object");
881     ok((arguments instanceof Array) === false, "argument is not instance of Array");
882     ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
883 })(1,2);
884
885 obj = new String();
886 ok(("length" in obj) === true, "length is not in obj");
887 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
888 ok(("abc" in obj) === false, "test is in obj");
889 obj.abc = 1;
890 ok(("abc" in obj) === true, "test is not in obj");
891 ok(("1" in obj) === false, "1 is in obj");
892
893 obj = [1,2,3];
894 ok((1 in obj) === true, "1 is not in obj");
895
896 obj = new Object();
897 try {
898     obj.prop["test"];
899     ok(false, "expected exception");
900 }catch(e) {}
901 ok(!("prop" in obj), "prop in obj");
902
903 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
904 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
905 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
906 ok(isNaN() === true, "isNaN() !== true");
907 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
908 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
909 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
910
911 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
912 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
913 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
914 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
915 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
916 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
917 ok(isFinite() === false, "isFinite() !== false");
918
919 ok((1 < NaN) === false, "(1 < NaN) !== false");
920 ok((1 > NaN) === false, "(1 > NaN) !== false");
921 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
922 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
923 ok((NaN < 1) === false, "(NaN < 1) !== false");
924 ok((NaN > 1) === false, "(NaN > 1) !== false");
925 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
926 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
927 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
928 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
929 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
930
931 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
932 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
933 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
934 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
935 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
936 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
937
938 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
939 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
940 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
941 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
942 ok((0 === NaN) === false, "(0 === NaN) !== false");
943
944 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
945 ok((NaN == NaN) === false, "(NaN === NaN) != false");
946 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
947 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
948 ok((0 == NaN) === false, "(0 === NaN) != false");
949
950 // escape tests
951 var escapeTests = [
952     ["\'", "\\'", 39],
953     ["\"", "\\\"", 34],
954     ["\\", "\\\\", 92],
955     ["\b", "\\b", 8],
956     ["\t", "\\t", 9],
957     ["\n", "\\n", 10],
958     ["\v", "\\v", 118],
959     ["\f", "\\f", 12],
960     ["\r", "\\r", 13],
961     ["\xf3", "\\xf3", 0xf3],
962     ["\u1234", "\\u1234", 0x1234],
963     ["\a", "\\a", 97],
964     ["\?", "\\?", 63]
965 ];
966
967 for(i=0; i<escapeTests.length; i++) {
968     tmp = escapeTests[i][0].charCodeAt(0);
969     ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]);
970 }
971
972 tmp = !+"\v1";
973 ok(tmp === true, '!+"\v1" = ' + tmp);
974
975 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
976 tmp = testFunc2(1);
977 ok(tmp === 2, "testFunc2(1) = " + tmp);
978 function testFunc2(x) { return x+1; }
979
980 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
981 tmp = testFunc3(1);
982 ok(tmp === 3, "testFunc3(1) = " + tmp);
983 tmp = function testFunc3(x) { return x+2; };
984
985 tmp = testFunc4(1);
986 ok(tmp === 5, "testFunc4(1) = " + tmp);
987 tmp = function testFunc4(x) { return x+3; };
988 tmp = testFunc4(1);
989 testFunc4 = 1;
990 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
991 ok(tmp === 5, "testFunc4(1) = " + tmp);
992 tmp = function testFunc4(x) { return x+4; };
993 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
994
995 function testEmbededFunctions() {
996     ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
997     tmp = testFunc5(1);
998     ok(tmp === 3, "testFunc5(1) = " + tmp);
999     tmp = function testFunc5(x) { return x+2; };
1000
1001     tmp = testFunc6(1);
1002     ok(tmp === 5, "testFunc6(1) = " + tmp);
1003     tmp = function testFunc6(x) { return x+3; };
1004     tmp = testFunc6(1);
1005     ok(tmp === 5, "testFunc6(1) = " + tmp);
1006     tmp = function testFunc6(x) { return x+4; };
1007     testFunc6 = 1;
1008     ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
1009 }
1010
1011 testEmbededFunctions();
1012
1013 date = new Date();
1014 date.toString = function() { return "toString"; }
1015 ok(""+date === "toString", "''+date = " + date);
1016 date.toString = function() { return this; }
1017 ok(""+date === ""+date.valueOf(), "''+date = " + date);
1018
1019 str = new String("test");
1020 str.valueOf = function() { return "valueOf"; }
1021 ok(""+str === "valueOf", "''+str = " + str);
1022 str.valueOf = function() { return new Date(); }
1023 ok(""+str === "test", "''+str = " + str);
1024
1025 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
1026
1027 var re = /=(\?|%3F)/g;
1028 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
1029
1030 tmp = new Array();
1031 for(var i=0; i<2; i++)
1032     tmp[i] = /b/;
1033 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
1034
1035 ok(createNullBSTR() === '', "createNullBSTR() !== ''");
1036
1037 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1038 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1039 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
1040 ok(nullDisp !== re, "nullDisp === re");
1041 ok(nullDisp === null, "nullDisp === null");
1042 ok(nullDisp == null, "nullDisp == null");
1043 ok(getVT(true && nullDisp) === "VT_DISPATCH",
1044    "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
1045 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1046 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1047 ok(nullDisp != new Object(), "nullDisp == new Object()");
1048 ok(new Object() != nullDisp, "new Object() == nullDisp");
1049 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1050 tmp = getVT(Object(nullDisp));
1051 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1052 tmp = Object(nullDisp).toString();
1053 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1054
1055 function do_test() {}
1056 function nosemicolon() {} nosemicolon();
1057 function () {} nosemicolon();
1058
1059 if(false) {
1060     function in_if_false() { return true; } ok(false, "!?");
1061 }
1062
1063 ok(in_if_false(), "in_if_false failed");
1064
1065 (function() { newValue = 1; })();
1066 ok(newValue === 1, "newValue = " + newValue);
1067
1068 obj = {undefined: 3};
1069
1070 /* Keep this test in the end of file */
1071 undefined = 6;
1072 ok(undefined === 6, "undefined = " + undefined);
1073
1074 NaN = 6;
1075 ok(NaN === 6, "NaN !== 6");
1076
1077 Infinity = 6;
1078 ok(Infinity === 6, "Infinity !== 6");
1079
1080 Math = 6;
1081 ok(Math === 6, "NaN !== 6");
1082
1083 reportSuccess();