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