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