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