TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / jscript / tests / lang.js
blob3e60aba76ad78bb460d891ade7cf33fba3b72da7
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  */
19 var tmp;
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");
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");
41 ok(00 === 0, "00 != 0");
42 ok(010 === 8, "010 != 8");
43 ok(077 === 63, "077 != 63");
44 ok(080 === 80, "080 != 80");
45 ok(090 === 90, "090 != 90");
46 ok(018 === 18, "018 != 18");
47 tmp = 07777777777777777777777;
48 ok(typeof(tmp) === "number" && tmp > 0xffffffff, "tmp = " + tmp);
49 tmp = 07777777779777777777777;
50 ok(typeof(tmp) === "number" && tmp > 0xffffffff, "tmp = " + tmp);
52 ok(1 !== 2, "1 !== 2 is false");
53 ok(null !== undefined, "null !== undefined is false");
55 ok(1 == 1, "1 == 1 is false");
56 ok(!(1 == 2), "!(1 == 2) is false");
57 ok(1.0 == 1, "1.0 == 1 is false");
58 ok("abc" == "abc", "\"abc\" == \"abc\" is false");
59 ok(true == true, "true == true is false");
60 ok(null == null, "null == null is false");
61 ok(undefined == undefined, "undefined == undefined is false");
62 ok(undefined == null, "undefined == null is false");
63 ok(true == 1, "true == 1 is false");
64 ok(!(true == 2), "true == 2");
65 ok(0 == false, "0 == false is false");
67 ok(1 != 2, "1 != 2 is false");
68 ok(false != 1, "false != 1 is false");
70 ok(this === test, "this !== test");
71 eval('ok(this === test, "this !== test");');
73 var trueVar = true;
74 ok(trueVar, "trueVar is not true");
76 ok(ScriptEngine.length === 0, "ScriptEngine.length is not 0");
78 function testFunc1(x, y) {
79     ok(this !== undefined, "this is undefined");
80     ok(x === true, "x is not true");
81     ok(y === "test", "y is not \"test\"");
82     ok(arguments.length === 2, "arguments.length is not 2");
83     ok(arguments["0"] === true, "arguments[0] is not true");
84     ok(arguments["1"] === "test", "arguments[1] is not \"test\"");
85     ok(arguments.callee === testFunc1, "arguments.calee !== testFunc1");
86     ok(testFunc1.arguments === arguments, "testFunc1.arguments = " + testFunc1.arguments);
88     x = false;
89     ok(arguments[0] === false, "arguments[0] is not false");
90     arguments[1] = "x";
91     ok(y === "x", "y = " + y);
92     ok(arguments[1] === "x", "arguments[1] = " + arguments[1]);
94     ok(arguments["0x0"] === undefined, "arguments['0x0'] = " + arguments["0x0"]);
95     ok(arguments["x"] === undefined, "arguments['x'] = " + arguments["x"]);
97     ok(this === test, "this !== test");
98     eval('ok(this === test, "this !== test");');
100     tmp = delete arguments;
101     ok(tmp === false, "arguments deleted");
102     ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments));
104     return true;
107 ok(testFunc1.length === 2, "testFunc1.length is not 2");
108 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
110 ok(Object.prototype !== undefined, "Object.prototype is undefined");
111 ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
112 ok(String.prototype !== undefined, "String.prototype is undefined");
113 ok(Array.prototype !== undefined, "Array.prototype is undefined");
114 ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
115 ok(Number.prototype !== undefined, "Number.prototype is undefined");
116 ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
117 ok(Math !== undefined, "Math is undefined");
118 ok(Math.prototype === undefined, "Math.prototype is not undefined");
119 ok(Function.prototype !== undefined, "Function.prototype is undefined");
120 ok(Function.prototype.prototype === undefined, "Function.prototype.prototype is not undefined");
121 ok(Date.prototype !== undefined, "Date.prototype is undefined");
122 ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
124 function testConstructor(constr, name, inst) {
125     ok(constr.prototype.constructor === constr, name + ".prototype.constructor !== " + name);
126     ok(constr.prototype.hasOwnProperty("constructor"), name + ".prototype.hasOwnProperty('constructor')");
128     if(!inst)
129         inst = new constr();
131     ok(inst.constructor === constr, "(new " + name + "()).constructor !== " + name);
132     ok(!inst.hasOwnProperty("constructor"), "(new " + name + "()).hasOwnProperty('constructor')");
135 testConstructor(Object, "Object");
136 testConstructor(String, "String");
137 testConstructor(Array, "Array");
138 testConstructor(Boolean, "Boolean");
139 testConstructor(Number, "Number");
140 testConstructor(RegExp, "RegExp", /x/);
141 testConstructor(Function, "Function");
142 testConstructor(Date, "Date");
143 testConstructor(VBArray, "VBArray", new VBArray(createArray()));
144 testConstructor(Error, "Error");
145 testConstructor(EvalError, "EvalError");
146 testConstructor(RangeError, "RangeError");
147 testConstructor(ReferenceError, "ReferenceError");
148 testConstructor(RegExpError, "RegExpError");
149 testConstructor(SyntaxError, "SyntaxError");
150 testConstructor(TypeError, "TypeError");
151 testConstructor(URIError, "URIError");
153 Function.prototype.test = true;
154 ok(testFunc1.test === true, "testFunc1.test !== true");
155 ok(Function.test === true, "Function.test !== true");
157 ok(typeof(0) === "number", "typeof(0) is not number");
158 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
159 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
160 ok(typeof("") === "string", "typeof(\"\") is not string");
161 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
162 ok(typeof(null) === "object", "typeof(null) is not object");
163 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
164 ok(typeof(Math) === "object", "typeof(Math) is not object");
165 ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
166 ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
167 ok(typeof(String) === "function", "typeof(String) is not function");
168 ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
169 ok(typeof(this) === "object", "typeof(this) is not object");
170 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
171 tmp = typeof((new Object()).doesnotexist);
172 ok(tmp === "undefined", "typeof((new Object).doesnotexist = " + tmp);
173 tmp = typeof(testObj.onlyDispID);
174 ok(tmp === "unknown", "typeof(testObj.onlyDispID) = " + tmp);
176 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
178 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
180 (tmp) = 3;
181 ok(tmp === 3, "tmp = " + tmp);
183 function testRecFunc(x) {
184     ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
185     if(x) {
186         testRecFunc(false);
187         ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
188         ok(testRecFunc.arguments[0] === true, "testRecFunc.arguments.x = " + testRecFunc.arguments[0]);
189     }
192 testRecFunc.arguments = 5;
193 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
194 testRecFunc(true);
195 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
197 tmp = (function() {1;})();
198 ok(tmp === undefined, "tmp = " + tmp);
199 tmp = eval("1;");
200 ok(tmp === 1, "tmp = " + tmp);
201 tmp = eval("1,2;");
202 ok(tmp === 2, "tmp = " + tmp);
203 tmp = eval("testNoRes(),2;");
204 ok(tmp === 2, "tmp = " + tmp);
205 tmp = eval("if(true) {3}");
206 ok(tmp === 3, "tmp = " + tmp);
207 eval("testRes(); testRes()");
208 tmp = eval("3; if(false) {4;} else {};;;")
209 ok(tmp === 3, "tmp = " + tmp);
211 testNoRes();
212 testRes() && testRes();
213 testNoRes(), testNoRes();
215 tmp = (function(){ return testNoRes(), testRes();})();
217 var obj1 = new Object();
218 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
219 ok(obj1.constructor === Object, "unexpected obj1.constructor");
220 obj1.test = true;
221 obj1.func = function () {
222     ok(this === obj1, "this is not obj1");
223     ok(this.test === true, "this.test is not true");
224     ok(arguments.length === 1, "arguments.length is not 1");
225     ok(arguments["0"] === true, "arguments[0] is not true");
226     ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
228     return "test";
231 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
233 function testConstr1() {
234     this.var1 = 1;
236     ok(this !== undefined, "this is undefined");
237     ok(arguments.length === 1, "arguments.length is not 1");
238     ok(arguments["0"] === true, "arguments[0] is not 1");
239     ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
241     return false;
244 testConstr1.prototype.pvar = 1;
245 ok(testConstr1.prototype.constructor === testConstr1, "testConstr1.prototype.constructor !== testConstr1");
247 var obj2 = new testConstr1(true);
248 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
249 ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
250 ok(obj2.pvar === 1, "obj2.pvar is not 1");
251 ok(!obj2.hasOwnProperty('constructor'), "obj2.hasOwnProperty('constructor')");
253 testConstr1.prototype.pvar = 2;
254 ok(obj2.pvar === 2, "obj2.pvar is not 2");
256 obj2.pvar = 3;
257 testConstr1.prototype.pvar = 1;
258 ok(obj2.pvar === 3, "obj2.pvar is not 3");
260 obj1 = new Object();
261 function testConstr3() {
262     return obj1;
265 obj2 = new testConstr3();
266 ok(obj1 === obj2, "obj1 != obj2");
268 function testConstr4() {
269     return 2;
272 obj2 = new testConstr3();
273 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
275 var obj3 = new Object;
276 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
278 for(var iter in "test")
279     ok(false, "unexpected forin call, test = " + iter);
281 for(var iter in null)
282     ok(false, "unexpected forin call, test = " + iter);
284 for(var iter in false)
285     ok(false, "unexpected forin call, test = " + iter);
287 for(var iter in pureDisp)
288     ok(false, "unexpected forin call in pureDisp object");
290 tmp = new Object();
291 ok(!tmp.nonexistent, "!tmp.nonexistent = " + !tmp.nonexistent);
292 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '!' expression")
294 tmp = new Object();
295 ok((~tmp.nonexistent) === -1, "!tmp.nonexistent = " + ~tmp.nonexistent);
296 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '~' expression")
298 tmp = new Object();
299 ok(isNaN(+tmp.nonexistent), "!tmp.nonexistent = " + (+tmp.nonexistent));
300 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '+' expression")
302 tmp = new Object();
303 tmp[tmp.nonexistent];
304 ok(!("nonexistent" in tmp), "nonexistent is in tmp after array expression")
306 tmp = 0;
307 if(true)
308     tmp = 1;
309 else
310     ok(false, "else evaluated");
311 ok(tmp === 1, "tmp !== 1, if not evaluated?");
313 tmp = 0;
314 if(1 === 0)
315     ok(false, "if evaluated");
316 else
317     tmp = 1;
318 ok(tmp === 1, "tmp !== 1, if not evaluated?");
320 if(false)
321     ok(false, "if(false) evaluated");
323 tmp = 0;
324 if(true)
325     tmp = 1;
326 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
328 if(false) {
329 }else {
332 var obj3 = { prop1: 1,  prop2: typeof(false) };
333 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
334 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
335 ok(obj3.constructor === Object, "unexpected obj3.constructor");
338     var blockVar = 1;
339     blockVar = 2;
341 ok(blockVar === 2, "blockVar !== 2");
343 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
344 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
346 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
347 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
348 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
349 ok(getVT(0.5) === "VT_R8", "getVT(0.5) is not VT_R8");
350 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
351 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
352 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
354 tmp = 2+2;
355 ok(tmp === 4, "2+2 !== 4");
356 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
358 tmp = 2+2.5;
359 ok(tmp === 4.5, "2+2.5 !== 4.5");
360 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
362 tmp = 1.5+2.5;
363 ok(tmp === 4, "1.4+2.5 !== 4");
364 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
366 tmp = 4-2;
367 ok(tmp === 2, "4-2 !== 2");
368 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
370 tmp = 4.5-2;
371 ok(tmp === 2.5, "4.5-2 !== 2.5");
372 ok(getVT(tmp) === "VT_R8", "getVT(4.5-2) !== VT_R8");
374 tmp = -2;
375 ok(tmp === 0-2, "-2 !== 0-2");
376 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
378 tmp = 2*3;
379 ok(tmp === 6, "2*3 !== 6");
380 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
382 tmp = 2*3.5;
383 ok(tmp === 7, "2*3.5 !== 7");
384 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
386 tmp = 2.5*3.5;
387 /* FIXME: the parser loses precision */
388 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
389 ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
390 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
392 tmp = 4/2;
393 ok(tmp === 2, "4/2 !== 2");
394 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
396 tmp = 4.5/1.5;
397 ok(tmp === 3, "4.5/1.5 !== 3");
398 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
400 tmp = 3/2;
401 ok(tmp === 1.5, "3/2 !== 1.5");
402 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
404 tmp = 3%2;
405 ok(tmp === 1, "3%2 = " + tmp);
407 tmp = 4%2;
408 ok(tmp ===0, "4%2 = " + tmp);
410 tmp = 3.5%1.5;
411 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
413 tmp = 3%true;
414 ok(tmp === 0, "3%true = " + tmp);
416 tmp = "ab" + "cd";
417 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
419 tmp = 1;
420 ok((tmp += 1) === 2, "tmp += 1 !== 2");
421 ok(tmp === 2, "tmp !== 2");
423 tmp = 2;
424 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
425 ok(tmp === 1, "tmp !=== 1");
427 tmp = 2;
428 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
429 ok(tmp === 3, "tmp !=== 3");
431 tmp = 5;
432 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
433 ok(tmp === 2.5, "tmp !=== 2.5");
435 tmp = 3;
436 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
437 ok(tmp === 1, "tmp !== 1");
439 tmp = 8;
440 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
442 tmp = 8;
443 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
445 tmp = 8;
446 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
448 tmp = 3 || ok(false, "second or expression called");
449 ok(tmp === 3, "3 || (...) is not 3");
451 tmp = false || 2;
452 ok(tmp === 2, "false || 2 is not 2");
454 tmp = 0 && ok(false, "second and expression called");
455 ok(tmp === 0, "0 && (...) is not 0");
457 tmp = true && "test";
458 ok(tmp === "test", "true && \"test\" is not \"test\"");
460 tmp = true && 0;
461 ok(tmp === 0, "true && 0 is not 0");
463 tmp = 3 | 4;
464 ok(tmp === 7, "3 | 4 !== 7");
465 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
467 tmp = 3.5 | 0;
468 ok(tmp === 3, "3.5 | 0 !== 3");
469 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
471 tmp = -3.5 | 0;
472 ok(tmp === -3, "-3.5 | 0 !== -3");
473 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
475 tmp = 0 | NaN;
476 ok(tmp === 0, "0 | NaN = " + tmp);
478 tmp = 0 | Infinity;
479 ok(tmp === 0, "0 | NaN = " + tmp);
481 tmp = 0 | (-Infinity);
482 ok(tmp === 0, "0 | NaN = " + tmp);
484 tmp = 10;
485 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
486 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
488 tmp = 3 & 5;
489 ok(tmp === 1, "3 & 5 !== 1");
490 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
492 tmp = 3.5 & 0xffff;
493 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
494 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
496 tmp = (-3.5) & 0xffffffff;
497 ok(tmp === -3, "-3.5 & 0xffff !== -3");
498 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
500 tmp = 2 << 3;
501 ok(tmp === 16, "2 << 3 = " + tmp);
503 tmp = 2 << 35;
504 ok(tmp === 16, "2 << 35 = " + tmp);
506 tmp = 8 >> 2;
507 ok(tmp === 2, "8 >> 2 = " + tmp);
509 tmp = -64 >> 4;
510 ok(tmp === -4, "-64 >> 4 = " + tmp);
512 tmp = 8 >>> 2;
513 ok(tmp === 2, "8 >> 2 = " + tmp);
515 tmp = -64 >>> 4;
516 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
518 tmp = 4 >>> NaN;
519 ok(tmp === 4, "4 >>> NaN = " + tmp);
521 tmp = 10;
522 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
523 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
525 tmp = 0xf0f0^0xff00;
526 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
527 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
529 tmp = 5;
530 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
531 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
533 tmp = ~1;
534 ok(tmp === -2, "~1 !== -2");
535 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
537 ok((3,4) === 4, "(3,4) !== 4");
539 ok(+3 === 3, "+3 !== 3");
540 ok(+true === 1, "+true !== 1");
541 ok(+false === 0, "+false !== 0");
542 ok(+null === 0, "+null !== 0");
543 ok(+"0" === 0, "+'0' !== 0");
544 ok(+"3" === 3, "+'3' !== 3");
545 ok(+"-3" === -3, "+'-3' !== -3");
546 ok(+"0xff" === 255, "+'0xff' !== 255");
547 ok(+"3e3" === 3000, "+'3e3' !== 3000");
549 tmp = new Number(1);
550 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
551 ok(tmp.constructor === Number, "unexpected tmp.constructor");
552 tmp = new String("1");
553 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
554 ok(tmp.constructor === String, "unexpected tmp.constructor");
556 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
557 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
558 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
559 ok("" + null === "null", "\"\" + null !== \"null\"");
560 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
561 ok("" + true === "true", "\"\" + true !== \"true\"");
562 ok("" + false === "false", "\"\" + false !== \"false\"");
563 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
564 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
566 ok(1 < 3.4, "1 < 3.4 failed");
567 ok(!(3.4 < 1), "3.4 < 1");
568 ok("abc" < "abcd", "abc < abcd failed");
569 ok("abcd" < "abce", "abce < abce failed");
570 ok("" < "x", "\"\" < \"x\" failed");
571 ok(!(0 < 0), "0 < 0");
573 ok(1 <= 3.4, "1 <= 3.4 failed");
574 ok(!(3.4 <= 1), "3.4 <= 1");
575 ok("abc" <= "abcd", "abc <= abcd failed");
576 ok("abcd" <= "abce", "abce <= abce failed");
577 ok("" <= "x", "\"\" <= \"x\" failed");
578 ok(0 <= 0, "0 <= 0 failed");
580 ok(3.4 > 1, "3.4 > 1 failed");
581 ok(!(1 > 3.4), "1 > 3.4");
582 ok("abcd" > "abc", "abc > abcd failed");
583 ok("abce" > "abcd", "abce > abce failed");
584 ok("x" > "", "\"x\" > \"\" failed");
585 ok(!(0 > 0), "0 > 0");
587 ok(3.4 >= 1, "3.4 >= 1 failed");
588 ok(!(1 >= 3.4), "1 >= 3.4");
589 ok("abcd" >= "abc", "abc >= abcd failed");
590 ok("abce" >= "abcd", "abce >= abce failed");
591 ok("x" >= "", "\"x\" >= \"\" failed");
592 ok(0 >= 0, "0 >= 0");
594 tmp = 1;
595 ok(++tmp === 2, "++tmp (1) is not 2");
596 ok(tmp === 2, "incremented tmp is not 2");
597 ok(--tmp === 1, "--tmp (2) is not 1");
598 ok(tmp === 1, "decremented tmp is not 1");
599 ok(tmp++ === 1, "tmp++ (1) is not 1");
600 ok(tmp === 2, "incremented tmp(1) is not 2");
601 ok(tmp-- === 2, "tmp-- (2) is not 2");
602 ok(tmp === 1, "decremented tmp is not 1");
604 tmp = new Object();
605 tmp.iii++;
606 ok(isNaN(tmp.iii), "tmp.iii = " + tmp.iii);
608 String.prototype.test = true;
609 ok("".test === true, "\"\".test is not true");
611 Boolean.prototype.test = true;
612 ok(true.test === true, "true.test is not true");
614 Number.prototype.test = true;
615 ok((0).test === true, "(0).test is not true");
616 ok((0.5).test === true, "(0.5).test is not true");
618 var state = "";
619 try {
620     ok(state === "", "try: state = " + state);
621     state = "try";
622 }catch(ex) {
623     ok(false, "unexpected catch");
625 ok(state === "try", "state = " + state + " expected try");
627 state = "";
628 try {
629     ok(state === "", "try: state = " + state);
630     state = "try";
631 }finally {
632     ok(state === "try", "finally: state = " + state);
633     state = "finally";
635 ok(state === "finally", "state = " + state + " expected finally");
637 state = "";
638 try {
639     try {
640         throw 0;
641     }finally {
642         state = "finally";
643     }
644 }catch(e) {
645     ok(state === "finally", "state = " + state + " expected finally");
646     state = "catch";
648 ok(state === "catch", "state = " + state + " expected catch");
650 try {
651     try {
652         throw 0;
653     }finally {
654         throw 1;
655     }
656 }catch(e) {
657     ok(e === 1, "e = " + e);
660 state = "";
661 try {
662     ok(state === "", "try: state = " + state);
663     state = "try";
664 }catch(ex) {
665     ok(false, "unexpected catch");
666 }finally {
667     ok(state === "try", "finally: state = " + state);
668     state = "finally";
670 ok(state === "finally", "state = " + state + " expected finally");
672 var state = "";
673 try {
674     ok(state === "", "try: state = " + state);
675     state = "try";
676     throw "except";
677 }catch(ex) {
678     ok(state === "try", "catch: state = " + state);
679     ok(ex === "except", "ex is not \"except\"");
680     state = "catch";
682 ok(state === "catch", "state = " + state + " expected catch");
684 var state = "";
685 try {
686     ok(state === "", "try: state = " + state);
687     state = "try";
688     throw true;
689 }catch(ex) {
690     ok(state === "try", "catch: state = " + state);
691     ok(ex === true, "ex is not true");
692     state = "catch";
693 }finally {
694     ok(state === "catch", "finally: state = " + state);
695     state = "finally";
697 ok(state === "finally", "state = " + state + " expected finally");
699 var state = "";
700 try {
701     ok(state === "", "try: state = " + state);
702     state = "try";
703     try { throw true; } finally {}
704 }catch(ex) {
705     ok(state === "try", "catch: state = " + state);
706     ok(ex === true, "ex is not true");
707     state = "catch";
708 }finally {
709     ok(state === "catch", "finally: state = " + state);
710     state = "finally";
712 ok(state === "finally", "state = " + state + " expected finally");
714 var state = "";
715 try {
716     ok(state === "", "try: state = " + state);
717     state = "try";
718     try { throw "except"; } catch(ex) { throw true; }
719 }catch(ex) {
720     ok(state === "try", "catch: state = " + state);
721     ok(ex === true, "ex is not true");
722     state = "catch";
723 }finally {
724     ok(state === "catch", "finally: state = " + state);
725     state = "finally";
727 ok(state === "finally", "state = " + state + " expected finally");
729 function throwFunc(x) {
730     throw x;
733 var state = "";
734 try {
735     ok(state === "", "try: state = " + state);
736     state = "try";
737     throwFunc(true);
738 }catch(ex) {
739     ok(state === "try", "catch: state = " + state);
740     ok(ex === true, "ex is not true");
741     state = "catch";
742 }finally {
743     ok(state === "catch", "finally: state = " + state);
744     state = "finally";
746 ok(state === "finally", "state = " + state + " expected finally");
748 state = "";
749 switch(1) {
750 case "1":
751     ok(false, "unexpected case \"1\"");
752 case 1:
753     ok(state === "", "case 1: state = " + state);
754     state = "1";
755 default:
756     ok(state === "1", "default: state = " + state);
757     state = "default";
758 case false:
759     ok(state === "default", "case false: state = " + state);
760     state = "false";
762 ok(state === "false", "state = " + state);
764 state = "";
765 switch("") {
766 case "1":
767 case 1:
768     ok(false, "unexpected case 1");
769 default:
770     ok(state === "", "default: state = " + state);
771     state = "default";
772 case false:
773     ok(state === "default", "case false: state = " + state);
774     state = "false";
776 ok(state === "false", "state = " + state);
778 state = "";
779 switch(1) {
780 case "1":
781     ok(false, "unexpected case \"1\"");
782 case 1:
783     ok(state === "", "case 1: state = " + state);
784     state = "1";
785 default:
786     ok(state === "1", "default: state = " + state);
787     state = "default";
788     break;
789 case false:
790     ok(false, "unexpected case false");
792 ok(state === "default", "state = " + state);
794 switch(1) {
795 case 2:
796     ok(false, "unexpected case 2");
797 case 3:
798     ok(false, "unexpected case 3");
801 switch(1) {
802 case 2:
803     ok(false, "unexpected case 2");
804     break;
805 default:
806     /* empty default */
809 switch(2) {
810 default:
811     ok(false, "unexpected default");
812     break;
813 case 2:
814     /* empty case */
817 switch(2) {
818 default:
819     ok(false, "unexpected default");
820     break;
821 case 1:
822 case 2:
823 case 3:
824     /* empty case */
827 (function() {
828     var i=0;
830     switch(1) {
831     case 1:
832         i++;
833     }
834     return i;
835 })();
837 tmp = eval("1");
838 ok(tmp === 1, "eval(\"1\") !== 1");
839 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
840 ok(tmp === 2, "tmp !== 2");
842 ok(eval(false) === false, "eval(false) !== false");
843 ok(eval() === undefined, "eval() !== undefined");
845 tmp = eval("1", "2");
846 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
848 var state = "";
849 try {
850     ok(state === "", "try: state = " + state);
851     state = "try";
852     eval("throwFunc(true);");
853 }catch(ex) {
854     ok(state === "try", "catch: state = " + state);
855     ok(ex === true, "ex is not true");
856     state = "catch";
857 }finally {
858     ok(state === "catch", "finally: state = " + state);
859     state = "finally";
861 ok(state === "finally", "state = " + state + " expected finally");
863 tmp = [,,1,2,,,true];
864 ok(tmp.length === 7, "tmp.length !== 7");
865 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
866 ok(tmp["3"] === 2, "tmp[3] !== 2");
867 ok(tmp["6"] === true, "tmp[6] !== true");
868 ok(tmp[2] === 1, "tmp[2] !== 1");
870 ok([1,].length === 2, "[1,].length !== 2");
871 ok([,,].length === 3, "[,,].length !== 3");
872 ok([,].length === 2, "[].length != 2");
873 ok([].length === 0, "[].length != 0");
875 tmp = 0;
876 while(tmp < 4) {
877     ok(tmp < 4, "tmp >= 4");
878     tmp++;
880 ok(tmp === 4, "tmp !== 4");
882 tmp = 0;
883 while(true) {
884     ok(tmp < 4, "tmp >= 4");
885     tmp++;
886     if(tmp === 4) {
887         break;
888         ok(false, "break did not break");
889     }
891 ok(tmp === 4, "tmp !== 4");
893 tmp = 0;
894 do {
895     ok(tmp < 4, "tmp >= 4");
896     tmp++;
897 } while(tmp < 4);
898 ok(tmp === 4, "tmp !== 4");
900 tmp = 0;
901 do {
902     ok(tmp === 0, "tmp !=== 0");
903     tmp++;
904 } while(false);
905 ok(tmp === 1, "tmp !== 1");
907 tmp = 0;
908 do {
909     ok(tmp < 4, "tmp >= 4");
910     tmp++;
911 } while(tmp < 4)
912 ok(tmp === 4, "tmp !== 4")
914 tmp = 0;
915 while(tmp < 4) {
916     tmp++;
917     if(tmp === 2) {
918         continue;
919         ok(false, "break did not break");
920     }
921     ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
923 ok(tmp === 4, "tmp !== 4");
925 for(tmp=0; tmp < 4; tmp++)
926     ok(tmp < 4, "tmp = " + tmp);
927 ok(tmp === 4, "tmp !== 4");
929 for(tmp=0; tmp < 4; tmp++) {
930     if(tmp === 2)
931         break;
932     ok(tmp < 2, "tmp = " + tmp);
934 ok(tmp === 2, "tmp !== 2");
936 for(tmp=0; tmp < 4; tmp++) {
937     if(tmp === 2)
938         continue;
939     ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
941 ok(tmp === 4, "tmp !== 4");
943 for(var fi=0; fi < 4; fi++)
944     ok(fi < 4, "fi = " + fi);
945 ok(fi === 4, "fi !== 4");
947 tmp = true;
948 obj1 = new Object();
949 for(obj1.nonexistent; tmp; tmp = false)
950     ok(!("nonexistent" in obj1), "nonexistent added to obj1");
952 obj1 = new Object();
953 for(tmp in obj1.nonexistent)
954     ok(false, "for(tmp in obj1.nonexistent) called with tmp = " + tmp);
955 ok(!("nonexistent" in obj1), "nonexistent added to obj1 by for..in loop");
958 var i, j;
960 /* Previous versions have broken finally block implementation */
961 if(ScriptEngineMinorVersion() >= 8) {
962     tmp = "";
963     i = 0;
964     while(true) {
965         tmp += "1";
966         for(i = 1; i < 3; i++) {
967             switch(i) {
968             case 1:
969                 tmp += "2";
970                 continue;
971             case 2:
972                 tmp += "3";
973                 try {
974                     throw null;
975                 }finally {
976                     tmp += "4";
977                     break;
978                 }
979             default:
980                 ok(false, "unexpected state");
981             }
982             tmp += "5";
983         }
984         with({prop: "6"}) {
985             tmp += prop;
986             break;
987         }
988     }
989     ok(tmp === "123456", "tmp = " + tmp);
992 tmp = "";
993 i = 0;
994 for(j in [1,2,3]) {
995     tmp += "1";
996     for(;;) {
997         with({prop: "2"}) {
998             tmp += prop;
999             try {
1000                 throw "3";
1001             }catch(e) {
1002                 tmp += e;
1003                 with([0])
1004                     break;
1005             }
1006         }
1007         ok(false, "unexpected state");
1008     }
1009     while(true) {
1010         tmp += "4";
1011         break;
1012     }
1013     break;
1015 ok(tmp === "1234", "tmp = " + tmp);
1017 tmp = 0;
1018 for(var iter in [1,2,3]) {
1019     tmp += +iter;
1020     continue;
1022 ok(tmp === 3, "tmp = " + tmp);
1024 tmp = false;
1025 for(var iter in [1,2,3]) {
1026     switch(+iter) {
1027     case 1:
1028         tmp = true;
1029         try {
1030             continue;
1031         }finally {}
1032     default:
1033         continue;
1034     }
1036 ok(tmp, "tmp = " + tmp);
1038 loop_label:
1039 while(true) {
1040     while(true)
1041         break loop_label;
1044 loop_label: {
1045     tmp = 0;
1046     while(true) {
1047         while(true)
1048             break loop_label;
1049     }
1050     ok(false, "unexpected evaluation 1");
1053 while(true) {
1054     some_label: break;
1055     ok(false, "unexpected evaluation 2");
1058 just_label: tmp = 1;
1059 ok(tmp === 1, "tmp != 1");
1061 some_label: break some_label;
1063 other_label: {
1064     break other_label;
1065     ok(false, "unexpected evaluation 3");
1068 loop_label:
1069 do {
1070     while(true)
1071         continue loop_label;
1072 }while(false);
1074 loop_label:
1075 for(i = 0; i < 3; i++) {
1076     while(true)
1077         continue loop_label;
1080 loop_label:
1081 other_label:
1082 for(i = 0; i < 3; i++) {
1083     while(true)
1084         continue loop_label;
1087 loop_label:
1088 for(tmp in {prop: false}) {
1089     while(true)
1090         continue loop_label;
1093 ok((void 1) === undefined, "(void 1) !== undefined");
1095 var inobj = new Object();
1097 for(var iter in inobj)
1098     ok(false, "unexpected iter = " + iter);
1100 inobj.test = true;
1101 tmp = 0;
1102 for(iter in inobj) {
1103     ok(iter == "test", "unexpected iter = " + iter);
1104     tmp++;
1106 ok(tmp === 1, "for..in tmp = " + tmp);
1108 function forinTestObj() {}
1110 forinTestObj.prototype.test3 = true;
1112 var arr = new Array();
1113 inobj = new forinTestObj();
1114 inobj.test1 = true;
1115 inobj.test2 = true;
1117 tmp = 0;
1118 for(iter in inobj) {
1119     arr[iter] = true;
1120     tmp++;
1123 ok(tmp === 3, "for..in tmp = " + tmp);
1124 ok(arr["test1"] === true, "arr[test1] !== true");
1125 ok(arr["test2"] === true, "arr[test2] !== true");
1126 ok(arr["test3"] === true, "arr[test3] !== true");
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 for(iter in tmp)
1134     ok(false, "tmp has prop " + iter);
1135 ok((delete tmp.test) === true, "deleting test didn't return true");
1136 ok((delete tmp.nonexistent) === true, "deleting nonexistent didn't return true");
1137 ok((delete nonexistent) === true, "deleting nonexistent didn't return true");
1139 tmp = new Object();
1140 tmp.test = false;
1141 ok((delete tmp["test"]) === true, "delete returned false");
1142 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1143 ok(!("test" in tmp), "test is still in tmp after delete?");
1145 tmp.testWith = true;
1146 with(tmp)
1147     ok(testWith === true, "testWith !== true");
1149 if(false) {
1150     var varTest1 = true;
1153 ok(varTest1 === undefined, "varTest1 = " + varTest1);
1154 ok(varTest2 === undefined, "varTest2 = " + varTest1);
1156 var varTest2;
1158 function varTestFunc(varTest3) {
1159     var varTest3;
1161     ok(varTest3 === 3, "varTest3 = " + varTest3);
1162     ok(varTest4 === undefined, "varTest4 = " + varTest4);
1164     var varTest4;
1167 varTestFunc(3);
1169 deleteTest = 1;
1170 delete deleteTest;
1171 try {
1172     tmp = deleteTest;
1173     ok(false, "deleteTest not throwed exception?");
1174 }catch(ex) {}
1176 if (false)
1177     if (true)
1178         ok(false, "if evaluated");
1179     else
1180         ok(false, "else should be associated with nearest if statement");
1182 if (true)
1183     if (false)
1184         ok(false, "if evaluated");
1185     else
1186         ok(true, "else should be associated with nearest if statement");
1188 function instanceOfTest() {}
1189 tmp = new instanceOfTest();
1191 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
1192 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1193 ok((tmp instanceof String) === false, "tmp is instance of String");
1195 instanceOfTest.prototype = new Object();
1196 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
1197 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1199 ok((1 instanceof Object) === false, "1 is instance of Object");
1200 ok((false instanceof Boolean) === false, "false is instance of Boolean");
1201 ok(("" instanceof Object) === false, "'' is instance of Object");
1203 (function () {
1204     ok((arguments instanceof Object) === true, "argument is not instance of Object");
1205     ok((arguments instanceof Array) === false, "argument is not instance of Array");
1206     ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
1207 })(1,2);
1209 obj = new String();
1210 ok(("length" in obj) === true, "length is not in obj");
1211 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
1212 ok(("abc" in obj) === false, "test is in obj");
1213 obj.abc = 1;
1214 ok(("abc" in obj) === true, "test is not in obj");
1215 ok(("1" in obj) === false, "1 is in obj");
1217 obj = [1,2,3];
1218 ok((1 in obj) === true, "1 is not in obj");
1220 obj = new Object();
1221 try {
1222     obj.prop["test"];
1223     ok(false, "expected exception");
1224 }catch(e) {}
1225 ok(!("prop" in obj), "prop in obj");
1227 if(invokeVersion >= 2) {
1228     ok("test"[0] === "t", '"test"[0] = ' + test[0]);
1229     ok("test"[5] === undefined, '"test"[0] = ' + test[0]);
1231     tmp = "test";
1232     ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1233     tmp[1] = "x";
1234     ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1235     ok(tmp["1"] === "e", "tmp['1'] = " + tmp["1"]);
1236     ok(tmp["0x1"] === undefined, "tmp['0x1'] = " + tmp["0x1"]);
1237 }else {
1238     ok("test"[0] === undefined, '"test"[0] = ' + test[0]);
1241 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
1242 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
1243 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
1244 ok(isNaN() === true, "isNaN() !== true");
1245 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
1246 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
1247 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
1249 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
1250 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
1251 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
1252 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
1253 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
1254 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
1255 ok(isFinite() === false, "isFinite() !== false");
1257 ok((1 < NaN) === false, "(1 < NaN) !== false");
1258 ok((1 > NaN) === false, "(1 > NaN) !== false");
1259 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
1260 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
1261 ok((NaN < 1) === false, "(NaN < 1) !== false");
1262 ok((NaN > 1) === false, "(NaN > 1) !== false");
1263 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
1264 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
1265 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
1266 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
1267 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
1269 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
1270 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
1271 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
1272 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
1273 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
1274 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
1276 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
1277 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
1278 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1279 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1280 ok((0 === NaN) === false, "(0 === NaN) !== false");
1282 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
1283 ok((NaN == NaN) === false, "(NaN === NaN) != false");
1284 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1285 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1286 ok((0 == NaN) === false, "(0 === NaN) != false");
1288 // escape tests
1289 var escapeTests = [
1290     ["\'", "\\'", 39],
1291     ["\"", "\\\"", 34],
1292     ["\\", "\\\\", 92],
1293     ["\b", "\\b", 8],
1294     ["\t", "\\t", 9],
1295     ["\n", "\\n", 10],
1296     ["\v", "\\v", 118],
1297     ["\f", "\\f", 12],
1298     ["\r", "\\r", 13],
1299     ["\xf3", "\\xf3", 0xf3],
1300     ["\u1234", "\\u1234", 0x1234],
1301     ["\a", "\\a", 97],
1302     ["\?", "\\?", 63]
1305 for(i=0; i<escapeTests.length; i++) {
1306     tmp = escapeTests[i][0].charCodeAt(0);
1307     ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]);
1310 tmp = !+"\v1";
1311 ok(tmp === true, '!+"\v1" = ' + tmp);
1313 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
1314 tmp = testFunc2(1);
1315 ok(tmp === 2, "testFunc2(1) = " + tmp);
1316 function testFunc2(x) { return x+1; }
1318 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
1319 tmp = testFunc3(1);
1320 ok(tmp === 3, "testFunc3(1) = " + tmp);
1321 tmp = function testFunc3(x) { return x+2; };
1323 tmp = testFunc4(1);
1324 ok(tmp === 5, "testFunc4(1) = " + tmp);
1325 tmp = function testFunc4(x) { return x+3; };
1326 tmp = testFunc4(1);
1327 testFunc4 = 1;
1328 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1329 ok(tmp === 5, "testFunc4(1) = " + tmp);
1330 tmp = function testFunc4(x) { return x+4; };
1331 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1333 function testEmbeddedFunctions() {
1334     ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
1335     tmp = testFunc5(1);
1336     ok(tmp === 3, "testFunc5(1) = " + tmp);
1337     tmp = function testFunc5(x) { return x+2; };
1339     tmp = testFunc6(1);
1340     ok(tmp === 5, "testFunc6(1) = " + tmp);
1341     tmp = function testFunc6(x) { return x+3; };
1342     tmp = testFunc6(1);
1343     ok(tmp === 5, "testFunc6(1) = " + tmp);
1344     tmp = function testFunc6(x) { return x+4; };
1345     testFunc6 = 1;
1346     ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
1349 testEmbeddedFunctions();
1351 date = new Date();
1352 date.toString = function() { return "toString"; }
1353 ok(""+date === "toString", "''+date = " + date);
1354 date.toString = function() { return this; }
1355 ok(""+date === ""+date.valueOf(), "''+date = " + date);
1357 str = new String("test");
1358 str.valueOf = function() { return "valueOf"; }
1359 ok(""+str === "valueOf", "''+str = " + str);
1360 str.valueOf = function() { return new Date(); }
1361 ok(""+str === "test", "''+str = " + str);
1363 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
1365 var re = /=(\?|%3F)/g;
1366 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
1368 tmp = new Array();
1369 for(var i=0; i<2; i++)
1370     tmp[i] = /b/;
1371 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
1373 ok(isNullBSTR(getNullBSTR()), "isNullBSTR(getNullBSTR()) failed\n");
1374 ok(getNullBSTR() === '', "getNullBSTR() !== ''");
1375 ok(+getNullBSTR() === 0 , "+getNullBTR() !=== 0");
1377 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1378 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1379 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
1380 ok(nullDisp !== re, "nullDisp === re");
1381 ok(nullDisp === null, "nullDisp === null");
1382 ok(nullDisp == null, "nullDisp == null");
1383 ok(getVT(true && nullDisp) === "VT_DISPATCH",
1384    "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
1385 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1386 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1387 ok(nullDisp != new Object(), "nullDisp == new Object()");
1388 ok(new Object() != nullDisp, "new Object() == nullDisp");
1389 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1390 tmp = getVT(Object(nullDisp));
1391 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1392 tmp = Object(nullDisp).toString();
1393 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1395 function do_test() {}
1396 function nosemicolon() {} nosemicolon();
1397 function () {} nosemicolon();
1399 if(false) {
1400     function in_if_false() { return true; } ok(false, "!?");
1403 ok(in_if_false(), "in_if_false failed");
1405 (function() { newValue = 1; })();
1406 ok(newValue === 1, "newValue = " + newValue);
1408 obj = {undefined: 3};
1410 ok(typeof(name_override_func) === "function", "typeof(name_override_func) = " + typeof(name_override_func));
1411 name_override_func = 3;
1412 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1413 function name_override_func() {};
1414 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1416 tmp = (function() {
1417     var ret = false;
1418     with({ret: true})
1419         return ret;
1420 })();
1421 ok(tmp, "tmp = " + tmp);
1423 /* NoNewline rule parser tests */
1424 while(true) {
1425     if(true) break
1426     tmp = false
1429 while(true) {
1430     if(true) break /*
1431                     * no semicolon, but comment present */
1432     tmp = false
1435 while(true) {
1436     if(true) break // no semicolon, but comment present
1437     tmp = false
1440 while(true) {
1441     break
1442     continue
1443     tmp = false
1446 function returnTest() {
1447     return
1448     true;
1451 ok(returnTest() === undefined, "returnTest = " + returnTest());
1453 ActiveXObject = 1;
1454 ok(ActiveXObject === 1, "ActiveXObject = " + ActiveXObject);
1456 Boolean = 1;
1457 ok(Boolean === 1, "Boolean = " + Boolean);
1459 Object = 1;
1460 ok(Object === 1, "Object = " + Object);
1462 Array = 1;
1463 ok(Array === 1, "Array = " + Array);
1465 Date = 1;
1466 ok(Date === 1, "Date = " + Date);
1468 Error = 1;
1469 ok(Error === 1, "Error = " + Error);
1471 /* Keep this test in the end of file */
1472 undefined = 6;
1473 ok(undefined === 6, "undefined = " + undefined);
1475 NaN = 6;
1476 ok(NaN === 6, "NaN !== 6");
1478 Infinity = 6;
1479 ok(Infinity === 6, "Infinity !== 6");
1481 Math = 6;
1482 ok(Math === 6, "NaN !== 6");
1484 reportSuccess();