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