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