wininet/tests: Add tests for a prematurely closed connection.
[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 ok(this === test, "this !== test");
60 eval('ok(this === test, "this !== test");');
61
62 var trueVar = true;
63 ok(trueVar, "trueVar is not true");
64
65 ok(ScriptEngine.length === 0, "ScriptEngine.length is not 0");
66
67 function testFunc1(x, y) {
68     ok(this !== undefined, "this is undefined");
69     ok(x === true, "x is not true");
70     ok(y === "test", "y is not \"test\"");
71     ok(arguments.length === 2, "arguments.length is not 2");
72     ok(arguments["0"] === true, "arguments[0] is not true");
73     ok(arguments["1"] === "test", "arguments[1] is not \"test\"");
74     ok(arguments.callee === testFunc1, "arguments.calee !== testFunc1");
75     ok(testFunc1.arguments === arguments, "testFunc1.arguments = " + testFunc1.arguments);
76
77     x = false;
78     ok(arguments[0] === false, "arguments[0] is not false");
79     arguments[1] = "x";
80     ok(y === "x", "y = " + y);
81     ok(arguments[1] === "x", "arguments[1] = " + arguments[1]);
82
83     ok(arguments["0x0"] === undefined, "arguments['0x0'] = " + arguments["0x0"]);
84     ok(arguments["x"] === undefined, "arguments['x'] = " + arguments["x"]);
85
86     ok(this === test, "this !== test");
87     eval('ok(this === test, "this !== test");');
88
89     tmp = delete arguments;
90     ok(tmp === false, "arguments deleted");
91     ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments));
92
93     return true;
94 }
95
96 ok(testFunc1.length === 2, "testFunc1.length is not 2");
97 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
98
99 ok(Object.prototype !== undefined, "Object.prototype is undefined");
100 ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
101 ok(String.prototype !== undefined, "String.prototype is undefined");
102 ok(Array.prototype !== undefined, "Array.prototype is undefined");
103 ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
104 ok(Number.prototype !== undefined, "Number.prototype is undefined");
105 ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
106 ok(Math !== undefined, "Math is undefined");
107 ok(Math.prototype === undefined, "Math.prototype is not undefined");
108 ok(Function.prototype !== undefined, "Function.prototype is undefined");
109 ok(Function.prototype.prototype === undefined, "Function.prototype.prototype is not undefined");
110 ok(Date.prototype !== undefined, "Date.prototype is undefined");
111 ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
112
113 function testConstructor(constr, name, inst) {
114     ok(constr.prototype.constructor === constr, name + ".prototype.constructor !== " + name);
115     ok(constr.prototype.hasOwnProperty("constructor"), name + ".prototype.hasOwnProperty('constructor')");
116
117     if(!inst)
118         inst = new constr();
119
120     ok(inst.constructor === constr, "(new " + name + "()).constructor !== " + name);
121     ok(!inst.hasOwnProperty("constructor"), "(new " + name + "()).hasOwnProperty('constructor')");
122 }
123
124 testConstructor(Object, "Object");
125 testConstructor(String, "String");
126 testConstructor(Array, "Array");
127 testConstructor(Boolean, "Boolean");
128 testConstructor(Number, "Number");
129 testConstructor(RegExp, "RegExp", /x/);
130 testConstructor(Function, "Function");
131 testConstructor(Date, "Date");
132 testConstructor(VBArray, "VBArray", new VBArray(createArray()));
133 testConstructor(Error, "Error");
134 testConstructor(EvalError, "EvalError");
135 testConstructor(RangeError, "RangeError");
136 testConstructor(ReferenceError, "ReferenceError");
137 testConstructor(RegExpError, "RegExpError");
138 testConstructor(SyntaxError, "SyntaxError");
139 testConstructor(TypeError, "TypeError");
140 testConstructor(URIError, "URIError");
141
142 Function.prototype.test = true;
143 ok(testFunc1.test === true, "testFunc1.test !== true");
144 ok(Function.test === true, "Function.test !== true");
145
146 ok(typeof(0) === "number", "typeof(0) is not number");
147 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
148 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
149 ok(typeof("") === "string", "typeof(\"\") is not string");
150 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
151 ok(typeof(null) === "object", "typeof(null) is not object");
152 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
153 ok(typeof(Math) === "object", "typeof(Math) is not object");
154 ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
155 ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
156 ok(typeof(String) === "function", "typeof(String) is not function");
157 ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
158 ok(typeof(this) === "object", "typeof(this) is not object");
159 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
160 tmp = typeof((new Object()).doesnotexist);
161 ok(tmp === "undefined", "typeof((new Object).doesnotexist = " + tmp);
162 tmp = typeof(testObj.onlyDispID);
163 ok(tmp === "unknown", "typeof(testObj.onlyDispID) = " + tmp);
164
165 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
166
167 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
168
169 (tmp) = 3;
170 ok(tmp === 3, "tmp = " + tmp);
171
172 function testRecFunc(x) {
173     ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
174     if(x) {
175         testRecFunc(false);
176         ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
177         ok(testRecFunc.arguments[0] === true, "testRecFunc.arguments.x = " + testRecFunc.arguments[0]);
178     }
179 }
180
181 testRecFunc.arguments = 5;
182 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
183 testRecFunc(true);
184 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
185
186 tmp = (function() {1;})();
187 ok(tmp === undefined, "tmp = " + tmp);
188 tmp = eval("1;");
189 ok(tmp === 1, "tmp = " + tmp);
190 tmp = eval("1,2;");
191 ok(tmp === 2, "tmp = " + tmp);
192 tmp = eval("testNoRes(),2;");
193 ok(tmp === 2, "tmp = " + tmp);
194 tmp = eval("if(true) {3}");
195 ok(tmp === 3, "tmp = " + tmp);
196 eval("testRes(); testRes()");
197 tmp = eval("3; if(false) {4;} else {};;;")
198 ok(tmp === 3, "tmp = " + tmp);
199
200 testNoRes();
201 testRes() && testRes();
202 testNoRes(), testNoRes();
203
204 tmp = (function(){ return testNoRes(), testRes();})();
205
206 var obj1 = new Object();
207 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
208 ok(obj1.constructor === Object, "unexpected obj1.constructor");
209 obj1.test = true;
210 obj1.func = function () {
211     ok(this === obj1, "this is not obj1");
212     ok(this.test === true, "this.test is not true");
213     ok(arguments.length === 1, "arguments.length is not 1");
214     ok(arguments["0"] === true, "arguments[0] is not true");
215     ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
216
217     return "test";
218 };
219
220 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
221
222 function testConstr1() {
223     this.var1 = 1;
224
225     ok(this !== undefined, "this is undefined");
226     ok(arguments.length === 1, "arguments.length is not 1");
227     ok(arguments["0"] === true, "arguments[0] is not 1");
228     ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
229
230     return false;
231 }
232
233 testConstr1.prototype.pvar = 1;
234 ok(testConstr1.prototype.constructor === testConstr1, "testConstr1.prototype.constructor !== testConstr1");
235
236 var obj2 = new testConstr1(true);
237 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
238 ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
239 ok(obj2.pvar === 1, "obj2.pvar is not 1");
240 ok(!obj2.hasOwnProperty('constructor'), "obj2.hasOwnProperty('constructor')");
241
242 testConstr1.prototype.pvar = 2;
243 ok(obj2.pvar === 2, "obj2.pvar is not 2");
244
245 obj2.pvar = 3;
246 testConstr1.prototype.pvar = 1;
247 ok(obj2.pvar === 3, "obj2.pvar is not 3");
248
249 obj1 = new Object();
250 function testConstr3() {
251     return obj1;
252 }
253
254 obj2 = new testConstr3();
255 ok(obj1 === obj2, "obj1 != obj2");
256
257 function testConstr4() {
258     return 2;
259 }
260
261 obj2 = new testConstr3();
262 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
263
264 var obj3 = new Object;
265 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
266
267 for(var iter in "test")
268     ok(false, "unexpected forin call, test = " + iter);
269
270 for(var iter in null)
271     ok(false, "unexpected forin call, test = " + iter);
272
273 for(var iter in false)
274     ok(false, "unexpected forin call, test = " + iter);
275
276 for(var iter in pureDisp)
277     ok(false, "unexpected forin call in pureDisp object");
278
279 tmp = new Object();
280 ok(!tmp.nonexistent, "!tmp.nonexistent = " + !tmp.nonexistent);
281 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '!' expression")
282
283 tmp = new Object();
284 ok((~tmp.nonexistent) === -1, "!tmp.nonexistent = " + ~tmp.nonexistent);
285 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '~' expression")
286
287 tmp = new Object();
288 ok(isNaN(+tmp.nonexistent), "!tmp.nonexistent = " + (+tmp.nonexistent));
289 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '+' expression")
290
291 tmp = new Object();
292 tmp[tmp.nonexistent];
293 ok(!("nonexistent" in tmp), "nonexistent is in tmp after array expression")
294
295 tmp = 0;
296 if(true)
297     tmp = 1;
298 else
299     ok(false, "else evaluated");
300 ok(tmp === 1, "tmp !== 1, if not evaluated?");
301
302 tmp = 0;
303 if(1 === 0)
304     ok(false, "if evaluated");
305 else
306     tmp = 1;
307 ok(tmp === 1, "tmp !== 1, if not evaluated?");
308
309 if(false)
310     ok(false, "if(false) evaluated");
311
312 tmp = 0;
313 if(true)
314     tmp = 1;
315 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
316
317 if(false) {
318 }else {
319 }
320
321 var obj3 = { prop1: 1,  prop2: typeof(false) };
322 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
323 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
324 ok(obj3.constructor === Object, "unexpected obj3.constructor");
325
326 {
327     var blockVar = 1;
328     blockVar = 2;
329 }
330 ok(blockVar === 2, "blockVar !== 2");
331
332 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
333 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
334
335 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
336 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
337 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
338 ok(getVT(0.5) === "VT_R8", "getVT(0.5) is not VT_R8");
339 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
340 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
341 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
342
343 tmp = 2+2;
344 ok(tmp === 4, "2+2 !== 4");
345 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
346
347 tmp = 2+2.5;
348 ok(tmp === 4.5, "2+2.5 !== 4.5");
349 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
350
351 tmp = 1.5+2.5;
352 ok(tmp === 4, "1.4+2.5 !== 4");
353 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
354
355 tmp = 4-2;
356 ok(tmp === 2, "4-2 !== 2");
357 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
358
359 tmp = 4.5-2;
360 ok(tmp === 2.5, "4.5-2 !== 2.5");
361 ok(getVT(tmp) === "VT_R8", "getVT(4.5-2) !== VT_R8");
362
363 tmp = -2;
364 ok(tmp === 0-2, "-2 !== 0-2");
365 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
366
367 tmp = 2*3;
368 ok(tmp === 6, "2*3 !== 6");
369 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
370
371 tmp = 2*3.5;
372 ok(tmp === 7, "2*3.5 !== 7");
373 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
374
375 tmp = 2.5*3.5;
376 /* FIXME: the parser loses precision */
377 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
378 ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
379 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
380
381 tmp = 4/2;
382 ok(tmp === 2, "4/2 !== 2");
383 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
384
385 tmp = 4.5/1.5;
386 ok(tmp === 3, "4.5/1.5 !== 3");
387 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
388
389 tmp = 3/2;
390 ok(tmp === 1.5, "3/2 !== 1.5");
391 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
392
393 tmp = 3%2;
394 ok(tmp === 1, "3%2 = " + tmp);
395
396 tmp = 4%2;
397 ok(tmp ===0, "4%2 = " + tmp);
398
399 tmp = 3.5%1.5;
400 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
401
402 tmp = 3%true;
403 ok(tmp === 0, "3%true = " + tmp);
404
405 tmp = "ab" + "cd";
406 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
407
408 tmp = 1;
409 ok((tmp += 1) === 2, "tmp += 1 !== 2");
410 ok(tmp === 2, "tmp !== 2");
411
412 tmp = 2;
413 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
414 ok(tmp === 1, "tmp !=== 1");
415
416 tmp = 2;
417 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
418 ok(tmp === 3, "tmp !=== 3");
419
420 tmp = 5;
421 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
422 ok(tmp === 2.5, "tmp !=== 2.5");
423
424 tmp = 3;
425 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
426 ok(tmp === 1, "tmp !== 1");
427
428 tmp = 8;
429 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
430
431 tmp = 8;
432 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
433
434 tmp = 8;
435 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
436
437 tmp = 3 || ok(false, "second or expression called");
438 ok(tmp === 3, "3 || (...) is not 3");
439
440 tmp = false || 2;
441 ok(tmp === 2, "false || 2 is not 2");
442
443 tmp = 0 && ok(false, "second and expression called");
444 ok(tmp === 0, "0 && (...) is not 0");
445
446 tmp = true && "test";
447 ok(tmp === "test", "true && \"test\" is not \"test\"");
448
449 tmp = true && 0;
450 ok(tmp === 0, "true && 0 is not 0");
451
452 tmp = 3 | 4;
453 ok(tmp === 7, "3 | 4 !== 7");
454 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
455
456 tmp = 3.5 | 0;
457 ok(tmp === 3, "3.5 | 0 !== 3");
458 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
459
460 tmp = -3.5 | 0;
461 ok(tmp === -3, "-3.5 | 0 !== -3");
462 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
463
464 tmp = 0 | NaN;
465 ok(tmp === 0, "0 | NaN = " + tmp);
466
467 tmp = 0 | Infinity;
468 ok(tmp === 0, "0 | NaN = " + tmp);
469
470 tmp = 0 | (-Infinity);
471 ok(tmp === 0, "0 | NaN = " + tmp);
472
473 tmp = 10;
474 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
475 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
476
477 tmp = 3 & 5;
478 ok(tmp === 1, "3 & 5 !== 1");
479 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
480
481 tmp = 3.5 & 0xffff;
482 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
483 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
484
485 tmp = (-3.5) & 0xffffffff;
486 ok(tmp === -3, "-3.5 & 0xffff !== -3");
487 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
488
489 tmp = 2 << 3;
490 ok(tmp === 16, "2 << 3 = " + tmp);
491
492 tmp = 2 << 35;
493 ok(tmp === 16, "2 << 35 = " + tmp);
494
495 tmp = 8 >> 2;
496 ok(tmp === 2, "8 >> 2 = " + tmp);
497
498 tmp = -64 >> 4;
499 ok(tmp === -4, "-64 >> 4 = " + tmp);
500
501 tmp = 8 >>> 2;
502 ok(tmp === 2, "8 >> 2 = " + tmp);
503
504 tmp = -64 >>> 4;
505 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
506
507 tmp = 4 >>> NaN;
508 ok(tmp === 4, "4 >>> NaN = " + tmp);
509
510 tmp = 10;
511 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
512 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
513
514 tmp = 0xf0f0^0xff00;
515 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
516 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
517
518 tmp = 5;
519 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
520 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
521
522 tmp = ~1;
523 ok(tmp === -2, "~1 !== -2");
524 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
525
526 ok((3,4) === 4, "(3,4) !== 4");
527
528 ok(+3 === 3, "+3 !== 3");
529 ok(+true === 1, "+true !== 1");
530 ok(+false === 0, "+false !== 0");
531 ok(+null === 0, "+null !== 0");
532 ok(+"0" === 0, "+'0' !== 0");
533 ok(+"3" === 3, "+'3' !== 3");
534 ok(+"-3" === -3, "+'-3' !== -3");
535 ok(+"0xff" === 255, "+'0xff' !== 255");
536 ok(+"3e3" === 3000, "+'3e3' !== 3000");
537
538 tmp = new Number(1);
539 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
540 ok(tmp.constructor === Number, "unexpected tmp.constructor");
541 tmp = new String("1");
542 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
543 ok(tmp.constructor === String, "unexpected tmp.constructor");
544
545 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
546 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
547 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
548 ok("" + null === "null", "\"\" + null !== \"null\"");
549 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
550 ok("" + true === "true", "\"\" + true !== \"true\"");
551 ok("" + false === "false", "\"\" + false !== \"false\"");
552 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
553 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
554
555 ok(1 < 3.4, "1 < 3.4 failed");
556 ok(!(3.4 < 1), "3.4 < 1");
557 ok("abc" < "abcd", "abc < abcd failed");
558 ok("abcd" < "abce", "abce < abce failed");
559 ok("" < "x", "\"\" < \"x\" failed");
560 ok(!(0 < 0), "0 < 0");
561
562 ok(1 <= 3.4, "1 <= 3.4 failed");
563 ok(!(3.4 <= 1), "3.4 <= 1");
564 ok("abc" <= "abcd", "abc <= abcd failed");
565 ok("abcd" <= "abce", "abce <= abce failed");
566 ok("" <= "x", "\"\" <= \"x\" failed");
567 ok(0 <= 0, "0 <= 0 failed");
568
569 ok(3.4 > 1, "3.4 > 1 failed");
570 ok(!(1 > 3.4), "1 > 3.4");
571 ok("abcd" > "abc", "abc > abcd failed");
572 ok("abce" > "abcd", "abce > abce failed");
573 ok("x" > "", "\"x\" > \"\" failed");
574 ok(!(0 > 0), "0 > 0");
575
576 ok(3.4 >= 1, "3.4 >= 1 failed");
577 ok(!(1 >= 3.4), "1 >= 3.4");
578 ok("abcd" >= "abc", "abc >= abcd failed");
579 ok("abce" >= "abcd", "abce >= abce failed");
580 ok("x" >= "", "\"x\" >= \"\" failed");
581 ok(0 >= 0, "0 >= 0");
582
583 tmp = 1;
584 ok(++tmp === 2, "++tmp (1) is not 2");
585 ok(tmp === 2, "incremented tmp is not 2");
586 ok(--tmp === 1, "--tmp (2) is not 1");
587 ok(tmp === 1, "decremented tmp is not 1");
588 ok(tmp++ === 1, "tmp++ (1) is not 1");
589 ok(tmp === 2, "incremented tmp(1) is not 2");
590 ok(tmp-- === 2, "tmp-- (2) is not 2");
591 ok(tmp === 1, "decremented tmp is not 1");
592
593 tmp = new Object();
594 tmp.iii++;
595 ok(isNaN(tmp.iii), "tmp.iii = " + tmp.iii);
596
597 String.prototype.test = true;
598 ok("".test === true, "\"\".test is not true");
599
600 Boolean.prototype.test = true;
601 ok(true.test === true, "true.test is not true");
602
603 Number.prototype.test = true;
604 ok((0).test === true, "(0).test is not true");
605 ok((0.5).test === true, "(0.5).test is not true");
606
607 var state = "";
608 try {
609     ok(state === "", "try: state = " + state);
610     state = "try";
611 }catch(ex) {
612     ok(false, "unexpected catch");
613 }
614 ok(state === "try", "state = " + state + " expected try");
615
616 state = "";
617 try {
618     ok(state === "", "try: state = " + state);
619     state = "try";
620 }finally {
621     ok(state === "try", "finally: state = " + state);
622     state = "finally";
623 }
624 ok(state === "finally", "state = " + state + " expected finally");
625
626 state = "";
627 try {
628     try {
629         throw 0;
630     }finally {
631         state = "finally";
632     }
633 }catch(e) {
634     ok(state === "finally", "state = " + state + " expected finally");
635     state = "catch";
636 }
637 ok(state === "catch", "state = " + state + " expected catch");
638
639 try {
640     try {
641         throw 0;
642     }finally {
643         throw 1;
644     }
645 }catch(e) {
646     ok(e === 1, "e = " + e);
647 }
648
649 state = "";
650 try {
651     ok(state === "", "try: state = " + state);
652     state = "try";
653 }catch(ex) {
654     ok(false, "unexpected catch");
655 }finally {
656     ok(state === "try", "finally: state = " + state);
657     state = "finally";
658 }
659 ok(state === "finally", "state = " + state + " expected finally");
660
661 var state = "";
662 try {
663     ok(state === "", "try: state = " + state);
664     state = "try";
665     throw "except";
666 }catch(ex) {
667     ok(state === "try", "catch: state = " + state);
668     ok(ex === "except", "ex is not \"except\"");
669     state = "catch";
670 }
671 ok(state === "catch", "state = " + state + " expected catch");
672
673 var state = "";
674 try {
675     ok(state === "", "try: state = " + state);
676     state = "try";
677     throw true;
678 }catch(ex) {
679     ok(state === "try", "catch: state = " + state);
680     ok(ex === true, "ex is not true");
681     state = "catch";
682 }finally {
683     ok(state === "catch", "finally: state = " + state);
684     state = "finally";
685 }
686 ok(state === "finally", "state = " + state + " expected finally");
687
688 var state = "";
689 try {
690     ok(state === "", "try: state = " + state);
691     state = "try";
692     try { throw true; } finally {}
693 }catch(ex) {
694     ok(state === "try", "catch: state = " + state);
695     ok(ex === true, "ex is not true");
696     state = "catch";
697 }finally {
698     ok(state === "catch", "finally: state = " + state);
699     state = "finally";
700 }
701 ok(state === "finally", "state = " + state + " expected finally");
702
703 var state = "";
704 try {
705     ok(state === "", "try: state = " + state);
706     state = "try";
707     try { throw "except"; } catch(ex) { throw true; }
708 }catch(ex) {
709     ok(state === "try", "catch: state = " + state);
710     ok(ex === true, "ex is not true");
711     state = "catch";
712 }finally {
713     ok(state === "catch", "finally: state = " + state);
714     state = "finally";
715 }
716 ok(state === "finally", "state = " + state + " expected finally");
717
718 function throwFunc(x) {
719     throw x;
720 }
721
722 var state = "";
723 try {
724     ok(state === "", "try: state = " + state);
725     state = "try";
726     throwFunc(true);
727 }catch(ex) {
728     ok(state === "try", "catch: state = " + state);
729     ok(ex === true, "ex is not true");
730     state = "catch";
731 }finally {
732     ok(state === "catch", "finally: state = " + state);
733     state = "finally";
734 }
735 ok(state === "finally", "state = " + state + " expected finally");
736
737 state = "";
738 switch(1) {
739 case "1":
740     ok(false, "unexpected case \"1\"");
741 case 1:
742     ok(state === "", "case 1: state = " + state);
743     state = "1";
744 default:
745     ok(state === "1", "default: state = " + state);
746     state = "default";
747 case false:
748     ok(state === "default", "case false: state = " + state);
749     state = "false";
750 }
751 ok(state === "false", "state = " + state);
752
753 state = "";
754 switch("") {
755 case "1":
756 case 1:
757     ok(false, "unexpected case 1");
758 default:
759     ok(state === "", "default: state = " + state);
760     state = "default";
761 case false:
762     ok(state === "default", "case false: state = " + state);
763     state = "false";
764 }
765 ok(state === "false", "state = " + state);
766
767 state = "";
768 switch(1) {
769 case "1":
770     ok(false, "unexpected case \"1\"");
771 case 1:
772     ok(state === "", "case 1: state = " + state);
773     state = "1";
774 default:
775     ok(state === "1", "default: state = " + state);
776     state = "default";
777     break;
778 case false:
779     ok(false, "unexpected case false");
780 }
781 ok(state === "default", "state = " + state);
782
783 switch(1) {
784 case 2:
785     ok(false, "unexpected case 2");
786 case 3:
787     ok(false, "unexpected case 3");
788 }
789
790 switch(1) {
791 case 2:
792     ok(false, "unexpected case 2");
793     break;
794 default:
795     /* empty default */
796 }
797
798 switch(2) {
799 default:
800     ok(false, "unexpected default");
801     break;
802 case 2:
803     /* empty case */
804 };
805
806 switch(2) {
807 default:
808     ok(false, "unexpected default");
809     break;
810 case 1:
811 case 2:
812 case 3:
813     /* empty case */
814 };
815
816 (function() {
817     var i=0;
818
819     switch(1) {
820     case 1:
821         i++;
822     }
823     return i;
824 })();
825
826 tmp = eval("1");
827 ok(tmp === 1, "eval(\"1\") !== 1");
828 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
829 ok(tmp === 2, "tmp !== 2");
830
831 ok(eval(false) === false, "eval(false) !== false");
832 ok(eval() === undefined, "eval() !== undefined");
833
834 tmp = eval("1", "2");
835 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
836
837 var state = "";
838 try {
839     ok(state === "", "try: state = " + state);
840     state = "try";
841     eval("throwFunc(true);");
842 }catch(ex) {
843     ok(state === "try", "catch: state = " + state);
844     ok(ex === true, "ex is not true");
845     state = "catch";
846 }finally {
847     ok(state === "catch", "finally: state = " + state);
848     state = "finally";
849 }
850 ok(state === "finally", "state = " + state + " expected finally");
851
852 tmp = [,,1,2,,,true];
853 ok(tmp.length === 7, "tmp.length !== 7");
854 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
855 ok(tmp["3"] === 2, "tmp[3] !== 2");
856 ok(tmp["6"] === true, "tmp[6] !== true");
857 ok(tmp[2] === 1, "tmp[2] !== 1");
858
859 ok([1,].length === 2, "[1,].length !== 2");
860 ok([,,].length === 3, "[,,].length !== 3");
861 ok([,].length === 2, "[].length != 2");
862 ok([].length === 0, "[].length != 0");
863
864 tmp = 0;
865 while(tmp < 4) {
866     ok(tmp < 4, "tmp >= 4");
867     tmp++;
868 }
869 ok(tmp === 4, "tmp !== 4");
870
871 tmp = 0;
872 while(true) {
873     ok(tmp < 4, "tmp >= 4");
874     tmp++;
875     if(tmp === 4) {
876         break;
877         ok(false, "break did not break");
878     }
879 }
880 ok(tmp === 4, "tmp !== 4");
881
882 tmp = 0;
883 do {
884     ok(tmp < 4, "tmp >= 4");
885     tmp++;
886 } while(tmp < 4);
887 ok(tmp === 4, "tmp !== 4");
888
889 tmp = 0;
890 do {
891     ok(tmp === 0, "tmp !=== 0");
892     tmp++;
893 } while(false);
894 ok(tmp === 1, "tmp !== 1");
895
896 tmp = 0;
897 do {
898     ok(tmp < 4, "tmp >= 4");
899     tmp++;
900 } while(tmp < 4)
901 ok(tmp === 4, "tmp !== 4")
902
903 tmp = 0;
904 while(tmp < 4) {
905     tmp++;
906     if(tmp === 2) {
907         continue;
908         ok(false, "break did not break");
909     }
910     ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
911 }
912 ok(tmp === 4, "tmp !== 4");
913
914 for(tmp=0; tmp < 4; tmp++)
915     ok(tmp < 4, "tmp = " + tmp);
916 ok(tmp === 4, "tmp !== 4");
917
918 for(tmp=0; tmp < 4; tmp++) {
919     if(tmp === 2)
920         break;
921     ok(tmp < 2, "tmp = " + tmp);
922 }
923 ok(tmp === 2, "tmp !== 2");
924
925 for(tmp=0; tmp < 4; tmp++) {
926     if(tmp === 2)
927         continue;
928     ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
929 }
930 ok(tmp === 4, "tmp !== 4");
931
932 for(var fi=0; fi < 4; fi++)
933     ok(fi < 4, "fi = " + fi);
934 ok(fi === 4, "fi !== 4");
935
936 tmp = true;
937 obj1 = new Object();
938 for(obj1.nonexistent; tmp; tmp = false)
939     ok(!("nonexistent" in obj1), "nonexistent added to obj1");
940
941 obj1 = new Object();
942 for(tmp in obj1.nonexistent)
943     ok(false, "for(tmp in obj1.nonexistent) called with tmp = " + tmp);
944 ok(!("nonexistent" in obj1), "nonexistent added to obj1 by for..in loop");
945
946
947 var i, j;
948
949 /* Previous versions have broken finally block implementation */
950 if(ScriptEngineMinorVersion() >= 8) {
951     tmp = "";
952     i = 0;
953     while(true) {
954         tmp += "1";
955         for(i = 1; i < 3; i++) {
956             switch(i) {
957             case 1:
958                 tmp += "2";
959                 continue;
960             case 2:
961                 tmp += "3";
962                 try {
963                     throw null;
964                 }finally {
965                     tmp += "4";
966                     break;
967                 }
968             default:
969                 ok(false, "unexpected state");
970             }
971             tmp += "5";
972         }
973         with({prop: "6"}) {
974             tmp += prop;
975             break;
976         }
977     }
978     ok(tmp === "123456", "tmp = " + tmp);
979 }
980
981 tmp = "";
982 i = 0;
983 for(j in [1,2,3]) {
984     tmp += "1";
985     for(;;) {
986         with({prop: "2"}) {
987             tmp += prop;
988             try {
989                 throw "3";
990             }catch(e) {
991                 tmp += e;
992                 with([0])
993                     break;
994             }
995         }
996         ok(false, "unexpected state");
997     }
998     while(true) {
999         tmp += "4";
1000         break;
1001     }
1002     break;
1003 }
1004 ok(tmp === "1234", "tmp = " + tmp);
1005
1006 tmp = 0;
1007 for(var iter in [1,2,3]) {
1008     tmp += +iter;
1009     continue;
1010 }
1011 ok(tmp === 3, "tmp = " + tmp);
1012
1013 tmp = false;
1014 for(var iter in [1,2,3]) {
1015     switch(+iter) {
1016     case 1:
1017         tmp = true;
1018         try {
1019             continue;
1020         }finally {}
1021     default:
1022         continue;
1023     }
1024 }
1025 ok(tmp, "tmp = " + tmp);
1026
1027 loop_label:
1028 while(true) {
1029     while(true)
1030         break loop_label;
1031 }
1032
1033 loop_label: {
1034     tmp = 0;
1035     while(true) {
1036         while(true)
1037             break loop_label;
1038     }
1039     ok(false, "unexpected evaluation 1");
1040 }
1041
1042 while(true) {
1043     some_label: break;
1044     ok(false, "unexpected evaluation 2");
1045 }
1046
1047 just_label: tmp = 1;
1048 ok(tmp === 1, "tmp != 1");
1049
1050 some_label: break some_label;
1051
1052 other_label: {
1053     break other_label;
1054     ok(false, "unexpected evaluation 3");
1055 }
1056
1057 loop_label:
1058 do {
1059     while(true)
1060         continue loop_label;
1061 }while(false);
1062
1063 loop_label:
1064 for(i = 0; i < 3; i++) {
1065     while(true)
1066         continue loop_label;
1067 }
1068
1069 loop_label:
1070 other_label:
1071 for(i = 0; i < 3; i++) {
1072     while(true)
1073         continue loop_label;
1074 }
1075
1076 loop_label:
1077 for(tmp in {prop: false}) {
1078     while(true)
1079         continue loop_label;
1080 }
1081
1082 ok((void 1) === undefined, "(void 1) !== undefined");
1083
1084 var inobj = new Object();
1085
1086 for(var iter in inobj)
1087     ok(false, "unexpected iter = " + iter);
1088
1089 inobj.test = true;
1090 tmp = 0;
1091 for(iter in inobj) {
1092     ok(iter == "test", "unexpected iter = " + iter);
1093     tmp++;
1094 }
1095 ok(tmp === 1, "for..in tmp = " + tmp);
1096
1097 function forinTestObj() {}
1098
1099 forinTestObj.prototype.test3 = true;
1100
1101 var arr = new Array();
1102 inobj = new forinTestObj();
1103 inobj.test1 = true;
1104 inobj.test2 = true;
1105
1106 tmp = 0;
1107 for(iter in inobj) {
1108     arr[iter] = true;
1109     tmp++;
1110 }
1111
1112 ok(tmp === 3, "for..in tmp = " + tmp);
1113 ok(arr["test1"] === true, "arr[test1] !== true");
1114 ok(arr["test2"] === true, "arr[test2] !== true");
1115 ok(arr["test3"] === true, "arr[test3] !== true");
1116
1117 tmp = new Object();
1118 tmp.test = false;
1119 ok((delete tmp.test) === true, "delete returned false");
1120 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1121 ok(!("test" in tmp), "test is still in tmp after delete?");
1122 for(iter in tmp)
1123     ok(false, "tmp has prop " + iter);
1124 ok((delete tmp.test) === true, "deleting test didn't return true");
1125 ok((delete tmp.nonexistent) === true, "deleting nonexistent didn't return true");
1126 ok((delete nonexistent) === true, "deleting nonexistent didn't return true");
1127
1128 tmp = new Object();
1129 tmp.test = false;
1130 ok((delete tmp["test"]) === true, "delete returned false");
1131 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1132 ok(!("test" in tmp), "test is still in tmp after delete?");
1133
1134 tmp.testWith = true;
1135 with(tmp)
1136     ok(testWith === true, "testWith !== true");
1137
1138 if(false) {
1139     var varTest1 = true;
1140 }
1141
1142 ok(varTest1 === undefined, "varTest1 = " + varTest1);
1143 ok(varTest2 === undefined, "varTest2 = " + varTest1);
1144
1145 var varTest2;
1146
1147 function varTestFunc(varTest3) {
1148     var varTest3;
1149
1150     ok(varTest3 === 3, "varTest3 = " + varTest3);
1151     ok(varTest4 === undefined, "varTest4 = " + varTest4);
1152
1153     var varTest4;
1154 }
1155
1156 varTestFunc(3);
1157
1158 deleteTest = 1;
1159 delete deleteTest;
1160 try {
1161     tmp = deleteTest;
1162     ok(false, "deleteTest not throwed exception?");
1163 }catch(ex) {}
1164
1165 if (false)
1166     if (true)
1167         ok(false, "if evaluated");
1168     else
1169         ok(false, "else should be associated with nearest if statement");
1170
1171 if (true)
1172     if (false)
1173         ok(false, "if evaluated");
1174     else
1175         ok(true, "else should be associated with nearest if statement");
1176
1177 function instanceOfTest() {}
1178 tmp = new instanceOfTest();
1179
1180 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
1181 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1182 ok((tmp instanceof String) === false, "tmp is instance of String");
1183
1184 instanceOfTest.prototype = new Object();
1185 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
1186 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1187
1188 ok((1 instanceof Object) === false, "1 is instance of Object");
1189 ok((false instanceof Boolean) === false, "false is instance of Boolean");
1190 ok(("" instanceof Object) === false, "'' is instance of Object");
1191
1192 (function () {
1193     ok((arguments instanceof Object) === true, "argument is not instance of Object");
1194     ok((arguments instanceof Array) === false, "argument is not instance of Array");
1195     ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
1196 })(1,2);
1197
1198 obj = new String();
1199 ok(("length" in obj) === true, "length is not in obj");
1200 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
1201 ok(("abc" in obj) === false, "test is in obj");
1202 obj.abc = 1;
1203 ok(("abc" in obj) === true, "test is not in obj");
1204 ok(("1" in obj) === false, "1 is in obj");
1205
1206 obj = [1,2,3];
1207 ok((1 in obj) === true, "1 is not in obj");
1208
1209 obj = new Object();
1210 try {
1211     obj.prop["test"];
1212     ok(false, "expected exception");
1213 }catch(e) {}
1214 ok(!("prop" in obj), "prop in obj");
1215
1216 if(invokeVersion >= 2) {
1217     ok("test"[0] === "t", '"test"[0] = ' + test[0]);
1218     ok("test"[5] === undefined, '"test"[0] = ' + test[0]);
1219
1220     tmp = "test";
1221     ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1222     tmp[1] = "x";
1223     ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1224     ok(tmp["1"] === "e", "tmp['1'] = " + tmp["1"]);
1225     ok(tmp["0x1"] === undefined, "tmp['0x1'] = " + tmp["0x1"]);
1226 }else {
1227     ok("test"[0] === undefined, '"test"[0] = ' + test[0]);
1228 }
1229
1230 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
1231 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
1232 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
1233 ok(isNaN() === true, "isNaN() !== true");
1234 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
1235 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
1236 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
1237
1238 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
1239 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
1240 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
1241 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
1242 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
1243 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
1244 ok(isFinite() === false, "isFinite() !== false");
1245
1246 ok((1 < NaN) === false, "(1 < NaN) !== false");
1247 ok((1 > NaN) === false, "(1 > NaN) !== false");
1248 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
1249 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
1250 ok((NaN < 1) === false, "(NaN < 1) !== false");
1251 ok((NaN > 1) === false, "(NaN > 1) !== false");
1252 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
1253 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
1254 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
1255 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
1256 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
1257
1258 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
1259 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
1260 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
1261 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
1262 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
1263 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
1264
1265 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
1266 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
1267 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1268 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1269 ok((0 === NaN) === false, "(0 === NaN) !== false");
1270
1271 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
1272 ok((NaN == NaN) === false, "(NaN === NaN) != false");
1273 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1274 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1275 ok((0 == NaN) === false, "(0 === NaN) != false");
1276
1277 // escape tests
1278 var escapeTests = [
1279     ["\'", "\\'", 39],
1280     ["\"", "\\\"", 34],
1281     ["\\", "\\\\", 92],
1282     ["\b", "\\b", 8],
1283     ["\t", "\\t", 9],
1284     ["\n", "\\n", 10],
1285     ["\v", "\\v", 118],
1286     ["\f", "\\f", 12],
1287     ["\r", "\\r", 13],
1288     ["\xf3", "\\xf3", 0xf3],
1289     ["\u1234", "\\u1234", 0x1234],
1290     ["\a", "\\a", 97],
1291     ["\?", "\\?", 63]
1292 ];
1293
1294 for(i=0; i<escapeTests.length; i++) {
1295     tmp = escapeTests[i][0].charCodeAt(0);
1296     ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]);
1297 }
1298
1299 tmp = !+"\v1";
1300 ok(tmp === true, '!+"\v1" = ' + tmp);
1301
1302 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
1303 tmp = testFunc2(1);
1304 ok(tmp === 2, "testFunc2(1) = " + tmp);
1305 function testFunc2(x) { return x+1; }
1306
1307 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
1308 tmp = testFunc3(1);
1309 ok(tmp === 3, "testFunc3(1) = " + tmp);
1310 tmp = function testFunc3(x) { return x+2; };
1311
1312 tmp = testFunc4(1);
1313 ok(tmp === 5, "testFunc4(1) = " + tmp);
1314 tmp = function testFunc4(x) { return x+3; };
1315 tmp = testFunc4(1);
1316 testFunc4 = 1;
1317 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1318 ok(tmp === 5, "testFunc4(1) = " + tmp);
1319 tmp = function testFunc4(x) { return x+4; };
1320 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1321
1322 function testEmbeddedFunctions() {
1323     ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
1324     tmp = testFunc5(1);
1325     ok(tmp === 3, "testFunc5(1) = " + tmp);
1326     tmp = function testFunc5(x) { return x+2; };
1327
1328     tmp = testFunc6(1);
1329     ok(tmp === 5, "testFunc6(1) = " + tmp);
1330     tmp = function testFunc6(x) { return x+3; };
1331     tmp = testFunc6(1);
1332     ok(tmp === 5, "testFunc6(1) = " + tmp);
1333     tmp = function testFunc6(x) { return x+4; };
1334     testFunc6 = 1;
1335     ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
1336 }
1337
1338 testEmbeddedFunctions();
1339
1340 date = new Date();
1341 date.toString = function() { return "toString"; }
1342 ok(""+date === "toString", "''+date = " + date);
1343 date.toString = function() { return this; }
1344 ok(""+date === ""+date.valueOf(), "''+date = " + date);
1345
1346 str = new String("test");
1347 str.valueOf = function() { return "valueOf"; }
1348 ok(""+str === "valueOf", "''+str = " + str);
1349 str.valueOf = function() { return new Date(); }
1350 ok(""+str === "test", "''+str = " + str);
1351
1352 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
1353
1354 var re = /=(\?|%3F)/g;
1355 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
1356
1357 tmp = new Array();
1358 for(var i=0; i<2; i++)
1359     tmp[i] = /b/;
1360 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
1361
1362 ok(isNullBSTR(getNullBSTR()), "isNullBSTR(getNullBSTR()) failed\n");
1363 ok(getNullBSTR() === '', "getNullBSTR() !== ''");
1364 ok(+getNullBSTR() === 0 , "+getNullBTR() !=== 0");
1365
1366 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1367 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1368 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
1369 ok(nullDisp !== re, "nullDisp === re");
1370 ok(nullDisp === null, "nullDisp === null");
1371 ok(nullDisp == null, "nullDisp == null");
1372 ok(getVT(true && nullDisp) === "VT_DISPATCH",
1373    "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
1374 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1375 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1376 ok(nullDisp != new Object(), "nullDisp == new Object()");
1377 ok(new Object() != nullDisp, "new Object() == nullDisp");
1378 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1379 tmp = getVT(Object(nullDisp));
1380 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1381 tmp = Object(nullDisp).toString();
1382 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1383
1384 function do_test() {}
1385 function nosemicolon() {} nosemicolon();
1386 function () {} nosemicolon();
1387
1388 if(false) {
1389     function in_if_false() { return true; } ok(false, "!?");
1390 }
1391
1392 ok(in_if_false(), "in_if_false failed");
1393
1394 (function() { newValue = 1; })();
1395 ok(newValue === 1, "newValue = " + newValue);
1396
1397 obj = {undefined: 3};
1398
1399 ok(typeof(name_override_func) === "function", "typeof(name_override_func) = " + typeof(name_override_func));
1400 name_override_func = 3;
1401 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1402 function name_override_func() {};
1403 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1404
1405 tmp = (function() {
1406     var ret = false;
1407     with({ret: true})
1408         return ret;
1409 })();
1410 ok(tmp, "tmp = " + tmp);
1411
1412 /* NoNewline rule parser tests */
1413 while(true) {
1414     if(true) break
1415     tmp = false
1416 }
1417
1418 while(true) {
1419     if(true) break /*
1420                     * no semicolon, but comment present */
1421     tmp = false
1422 }
1423
1424 while(true) {
1425     if(true) break // no semicolon, but comment present
1426     tmp = false
1427 }
1428
1429 while(true) {
1430     break
1431     continue
1432     tmp = false
1433 }
1434
1435 function returnTest() {
1436     return
1437     true;
1438 }
1439
1440 ok(returnTest() === undefined, "returnTest = " + returnTest());
1441
1442 /* Keep this test in the end of file */
1443 undefined = 6;
1444 ok(undefined === 6, "undefined = " + undefined);
1445
1446 NaN = 6;
1447 ok(NaN === 6, "NaN !== 6");
1448
1449 Infinity = 6;
1450 ok(Infinity === 6, "Infinity !== 6");
1451
1452 Math = 6;
1453 ok(Math === 6, "NaN !== 6");
1454
1455 reportSuccess();