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