winegstreamer: Move seeking to the Unix library.
[wine.git] / dlls / jscript / tests / lang.js
blob753b4ee595e7fbf184c17d0aaf6297a5479907b3
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);
51 ok(0xffffffff === 4294967295, "0xffffffff = " + 0xffffffff);
52 tmp = 0x10000000000000000000000000000000000000000000000000000000000000000;
53 ok(tmp === Math.pow(2, 256), "0x1000...00 != 2^256");
55 ok(1 !== 2, "1 !== 2 is false");
56 ok(null !== undefined, "null !== undefined is false");
58 ok(1 == 1, "1 == 1 is false");
59 ok(!(1 == 2), "!(1 == 2) is false");
60 ok(1.0 == 1, "1.0 == 1 is false");
61 ok("abc" == "abc", "\"abc\" == \"abc\" is false");
62 ok(true == true, "true == true is false");
63 ok(null == null, "null == null is false");
64 ok(undefined == undefined, "undefined == undefined is false");
65 ok(undefined == null, "undefined == null is false");
66 ok(true == 1, "true == 1 is false");
67 ok(!(true == 2), "true == 2");
68 ok(0 == false, "0 == false is false");
70 ok(1 != 2, "1 != 2 is false");
71 ok(false != 1, "false != 1 is false");
73 ok(this === test, "this !== test");
74 eval('ok(this === test, "this !== test");');
76 var trueVar = true;
77 ok(trueVar, "trueVar is not true");
79 ok(ScriptEngine.length === 0, "ScriptEngine.length is not 0");
81 function testFunc1(x, y) {
82     ok(this !== undefined, "this is undefined");
83     ok(x === true, "x is not true");
84     ok(y === "test", "y is not \"test\"");
85     ok(arguments.length === 2, "arguments.length is not 2");
86     ok(arguments["0"] === true, "arguments[0] is not true");
87     ok(arguments["1"] === "test", "arguments[1] is not \"test\"");
88     ok(arguments.callee === testFunc1, "arguments.calee !== testFunc1");
89     ok(testFunc1.arguments === arguments, "testFunc1.arguments = " + testFunc1.arguments);
91     x = false;
92     ok(arguments[0] === false, "arguments[0] is not false");
93     arguments[1] = "x";
94     ok(y === "x", "y = " + y);
95     ok(arguments[1] === "x", "arguments[1] = " + arguments[1]);
97     ok(arguments["0x0"] === undefined, "arguments['0x0'] = " + arguments["0x0"]);
98     ok(arguments["x"] === undefined, "arguments['x'] = " + arguments["x"]);
100     ok(this === test, "this !== test");
101     eval('ok(this === test, "this !== test");');
103     tmp = delete arguments;
104     ok(tmp === false, "arguments deleted");
105     ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments));
107     x = 2;
108     ok(x === 2, "x = " + x);
109     ok(arguments[0] === 2, "arguments[0] = " + arguments[0]);
111     return true;
114 ok(testFunc1.length === 2, "testFunc1.length is not 2");
115 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
117 ok(Object.prototype !== undefined, "Object.prototype is undefined");
118 ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
119 ok(String.prototype !== undefined, "String.prototype is undefined");
120 ok(Array.prototype !== undefined, "Array.prototype is undefined");
121 ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
122 ok(Number.prototype !== undefined, "Number.prototype is undefined");
123 ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
124 ok(Math !== undefined, "Math is undefined");
125 ok(Math.prototype === undefined, "Math.prototype is not undefined");
126 ok(Function.prototype !== undefined, "Function.prototype is undefined");
127 ok(Function.prototype.prototype === undefined, "Function.prototype.prototype is not undefined");
128 ok(Date.prototype !== undefined, "Date.prototype is undefined");
129 ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
131 function testConstructor(constr, name, inst) {
132     ok(constr.prototype.constructor === constr, name + ".prototype.constructor !== " + name);
133     ok(constr.prototype.hasOwnProperty("constructor"), name + ".prototype.hasOwnProperty('constructor')");
135     if(!inst)
136         inst = new constr();
138     ok(inst.constructor === constr, "(new " + name + "()).constructor !== " + name);
139     ok(!inst.hasOwnProperty("constructor"), "(new " + name + "()).hasOwnProperty('constructor')");
142 testConstructor(Object, "Object");
143 testConstructor(String, "String");
144 testConstructor(Array, "Array");
145 testConstructor(Boolean, "Boolean");
146 testConstructor(Number, "Number");
147 testConstructor(RegExp, "RegExp", /x/);
148 testConstructor(Function, "Function");
149 testConstructor(Date, "Date");
150 testConstructor(VBArray, "VBArray", new VBArray(createArray()));
151 testConstructor(Error, "Error");
152 testConstructor(EvalError, "EvalError");
153 testConstructor(RangeError, "RangeError");
154 testConstructor(ReferenceError, "ReferenceError");
155 testConstructor(RegExpError, "RegExpError");
156 testConstructor(SyntaxError, "SyntaxError");
157 testConstructor(TypeError, "TypeError");
158 testConstructor(URIError, "URIError");
160 Function.prototype.test = true;
161 ok(testFunc1.test === true, "testFunc1.test !== true");
162 ok(Function.test === true, "Function.test !== true");
164 ok(typeof(0) === "number", "typeof(0) is not number");
165 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
166 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
167 ok(typeof("") === "string", "typeof(\"\") is not string");
168 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
169 ok(typeof(null) === "object", "typeof(null) is not object");
170 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
171 ok(typeof(Math) === "object", "typeof(Math) is not object");
172 ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
173 ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
174 ok(typeof(String) === "function", "typeof(String) is not function");
175 ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
176 ok(typeof(this) === "object", "typeof(this) is not object");
177 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
178 tmp = typeof((new Object()).doesnotexist);
179 ok(tmp === "undefined", "typeof((new Object).doesnotexist = " + tmp);
180 tmp = typeof(testObj.onlyDispID);
181 ok(tmp === "unknown", "typeof(testObj.onlyDispID) = " + tmp);
183 ok("\0\0x\0\0".length === 5, "\"\\0\\0x\\0\\0\".length = " + "\0\0x\0\0".length);
184 ok("\0\0x\0\0" === String.fromCharCode(0) + "\0x\0" + String.fromCharCode(0), "\"\\0\\0x\\0\\0\" unexpected");
186 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
188 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
190 (tmp) = 3;
191 ok(tmp === 3, "tmp = " + tmp);
193 (function() {
194     /* VT_DATE handling */
195     var d, e;
196     ok(getVT(v_date(0)) === "VT_DATE", "vt v_date(0) = " + getVT(v_date(0)));
197     d = v_date(0);
198     e = Date.parse("Sat Dec 30 00:00:00 1899");
199     ok(getVT(d) === "VT_DATE", "vt v_date(0) = " + getVT(d));
200     ok(getVT(+d) === "VT_R8", "vt +v_date(0) = " + getVT(d));
201     ok(getVT(d / d) === "VT_I4", "vt v_date(0) / v_date(0) = " + getVT(d / d));
202     ok((+d) === e, "+v_date(0) = " + (+d) + " expected " + e);
203     ok(("" + d).match(/^Sat Dec 30 00:00:00 .* 1899$/) != null, "+v_date(0) = " + d);
204     ok(d != d, "date d == d");
206     d = v_date(2.5);
207     e = Date.parse("Mon Jan 1 12:00:00 1900");
208     ok((+d) === e, "+v_date(2.5) = " + (+d));
209     ok(("" + d).match(/^Mon Jan 1 12:00:00 .* 1900$/) != null, "+v_date(2.5) = " + d);
211     d = v_date(42091);
212     e = Date.parse("Sat Mar 28 00:00:00 2015");
213     ok((+d) === e, "+v_date(2015y) = " + (+d) + " expected " + e);
214     ok(("" + d).match(/^Sat Mar 28 00:00:00 .* 2015$/) != null, "+v_date(2015y) = " + d);
215     ok(d != d, "date d == d");
216 })();
218 (function() {
219     /* VT_CY handling */
220     var d;
221     todo_wine_ok(getVT(v_cy(0)) === "VT_R8", "vt v_cy(0) = " + getVT(v_cy(0)));
222     todo_wine_ok(getVT(v_cy(10000)) === "VT_R8", "vt v_cy(10000) = " + getVT(v_cy(0)));
223     d = v_cy(0);
224     todo_wine_ok(getVT(d) === "VT_R8", "vt v_cy(0) = " + getVT(d));
225     todo_wine_ok(getVT(+d) === "VT_R8", "vt +v_cy(0) = " + getVT(d));
226     ok(d == 0, "v_cy(0) != 0\n");
227     ok(d === 0, "v_cy(0) !== 0\n");
228     ok("" + d === "0", "str(v_cy(0)) = " + d);
229     ok(d === d, "date d !== d");
231     d = v_cy(1000);
232     ok(getVT(d) === "VT_R8", "vt v_cy(1000) = " + getVT(d));
233     ok(getVT(+d) === "VT_R8", "vt +v_cy(1000) = " + getVT(d));
234     ok(d == 0.1, "v_cy(1000) != 0, d = " + d);
235     ok(d === 0.1, "v_cy(1000) !== 0.1\n");
236     ok("" + d === "0.1", "str(v_cy(1000)) = " + d);
237     ok(d === d, "date d !== d");
239     d = v_cy(25000);
240     ok(getVT(d) === "VT_R8", "vt v_cy(25000) = " + getVT(d));
241     ok(getVT(+d) === "VT_R8", "vt +v_cy(25000) = " + getVT(d));
242     ok(d === 2.5, "v_cy(25000) !== 2.5\n");
243     ok("" + d === "2.5", "str(v_cy(25000)) = " + d);
244 })();
246 function testRecFunc(x) {
247     ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
248     if(x) {
249         testRecFunc(false);
250         ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
251         ok(testRecFunc.arguments[0] === true, "testRecFunc.arguments.x = " + testRecFunc.arguments[0]);
252     }
255 testRecFunc.arguments = 5;
256 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
257 testRecFunc(true);
258 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
260 function argumentsTest() {
261     var save = arguments;
262     with({arguments: 1}) {
263         ok(arguments === 1, "arguments = " + arguments);
264         (function() {
265             ok(argumentsTest.arguments === save, "unexpected argumentsTest.arguments");
266         })();
267     }
268     eval('ok(arguments === save, "unexpected arguments");');
269     [1,2].sort(function() {
270         ok(argumentsTest.arguments === save, "unexpected argumentsTest.arguments");
271         return 1;
272     });
275 argumentsTest();
277 // arguments object detached from its execution context
278 (function() {
279     var args, get_x, set_x;
281     function test_args(detached) {
282         ok(args[0] === 1, "args[0] = " + args[0]);
283         set_x(2);
284         ok(args[0] === (detached ? 1 : 2), "args[0] = " + args[0] + " expected " + (detached ? 1 : 2));
285         args[0] = 3;
286         ok(get_x() === (detached ? 2 : 3), "get_x() = " + get_x());
287         ok(args[0] === 3, "args[0] = " + args[0]);
288     }
290     (function(x) {
291         args = arguments;
292         get_x = function() { return x; };
293         set_x = function(v) { x = v; };
295         test_args(false);
296         x = 1;
297     })(1);
299     test_args(true);
300 })();
302 // arguments is a regular variable, it may be overwritten
303 (function() {
304     ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments));
305     arguments = 1;
306     ok(arguments === 1, "arguments = " + arguments);
307 })();
309 (function callAsExprTest() {
310     ok(callAsExprTest.arguments === null, "callAsExprTest.arguments = " + callAsExprTest.arguments);
311 })(1,2);
313 tmp = (function() {1;})();
314 ok(tmp === undefined, "tmp = " + tmp);
315 tmp = eval("1;");
316 ok(tmp === 1, "tmp = " + tmp);
317 tmp = eval("1,2;");
318 ok(tmp === 2, "tmp = " + tmp);
319 tmp = eval("testNoRes(),2;");
320 ok(tmp === 2, "tmp = " + tmp);
321 tmp = eval("if(true) {3}");
322 ok(tmp === 3, "tmp = " + tmp);
323 eval("testRes(); testRes()");
324 tmp = eval("3; if(false) {4;} else {};;;")
325 ok(tmp === 3, "tmp = " + tmp);
326 tmp = eval("try { 1; } finally { 2; }")
327 ok(tmp === 2, "tmp = " + tmp);
329 testNoRes();
330 testRes() && testRes();
331 testNoRes(), testNoRes();
333 (function() {
334     eval("var x=1;");
335     ok(x === 1, "x = " + x);
336 })();
338 (function() {
339     var e = eval;
340     var r = e(1);
341     ok(r === 1, "r = " + r);
342     (function(x, a) { x(a); })(eval, "2");
343 })();
345 (function(r) {
346     r = eval("1");
347     ok(r === 1, "r = " + r);
348     (function(x, a) { x(a); })(eval, "2");
349 })();
351 tmp = (function(){ return testNoRes(), testRes();})();
353 var f1, f2;
355 ok(funcexpr() == 2, "funcexpr() = " + funcexpr());
357 f1 = function funcexpr() { return 1; }
358 ok(f1 != funcexpr, "f1 == funcexpr");
359 ok(f1() === 1, "f1() = " + f1());
361 f2 = function funcexpr() { return 2; }
362 ok(f2 != funcexpr, "f2 != funcexpr");
363 ok(f2() === 2, "f2() = " + f2());
365 f1 = null;
366 for(i = 0; i < 3; i++) {
367     f2 = function funcexpr2() {};
368     ok(f1 != f2, "f1 == f2");
369     f1 = f2;
372 f1 = null;
373 for(i = 0; i < 3; i++) {
374     f2 = function() {};
375     ok(f1 != f2, "f1 == f2");
376     f1 = f2;
379 (function() {
380     ok(infuncexpr() == 2, "infuncexpr() = " + infuncexpr());
382     f1 = function infuncexpr() { return 1; }
383     ok(f1 != funcexpr, "f1 == funcexpr");
384     ok(f1() === 1, "f1() = " + f1());
386     f2 = function infuncexpr() { return 2; }
387     ok(f2 != funcexpr, "f2 != funcexpr");
388     ok(f2() === 2, "f2() = " + f2());
390     f1 = null;
391     for(i = 0; i < 3; i++) {
392         f2 = function infuncexpr2() {};
393         ok(f1 != f2, "f1 == f2");
394         f1 = f2;
395     }
397     f1 = null;
398     for(i = 0; i < 3; i++) {
399         f2 = function() {};
400         ok(f1 != f2, "f1 == f2");
401         f1 = f2;
402     }
403 })();
405 var obj1 = new Object();
406 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
407 ok(obj1.constructor === Object, "unexpected obj1.constructor");
408 obj1.test = true;
409 obj1.func = function () {
410     ok(this === obj1, "this is not obj1");
411     ok(this.test === true, "this.test is not true");
412     ok(arguments.length === 1, "arguments.length is not 1");
413     ok(arguments["0"] === true, "arguments[0] is not true");
414     ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
416     return "test";
419 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
421 function testConstr1() {
422     this.var1 = 1;
424     ok(this !== undefined, "this is undefined");
425     ok(arguments.length === 1, "arguments.length is not 1");
426     ok(arguments["0"] === true, "arguments[0] is not 1");
427     ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
429     return false;
432 testConstr1.prototype.pvar = 1;
433 ok(testConstr1.prototype.constructor === testConstr1, "testConstr1.prototype.constructor !== testConstr1");
435 var obj2 = new testConstr1(true);
436 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
437 ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
438 ok(obj2.pvar === 1, "obj2.pvar is not 1");
439 ok(!obj2.hasOwnProperty('constructor'), "obj2.hasOwnProperty('constructor')");
441 testConstr1.prototype.pvar = 2;
442 ok(obj2.pvar === 2, "obj2.pvar is not 2");
444 obj2.pvar = 3;
445 testConstr1.prototype.pvar = 1;
446 ok(obj2.pvar === 3, "obj2.pvar is not 3");
448 obj1 = new Object();
449 function testConstr3() {
450     return obj1;
453 obj2 = new testConstr3();
454 ok(obj1 === obj2, "obj1 != obj2");
456 function testConstr4() {
457     return 2;
460 obj2 = new testConstr3();
461 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
463 var obj3 = new Object;
464 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
466 (function() {
467     ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
468     function func() {}
469     ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
470     func = 0;
471     ok(typeof(func) === "number", "typeof(func) = " + typeof(func));
472 })();
474 (function(f) {
475     ok(typeof(f) === "function", "typeof(f) = " + typeof(f));
476     function f() {};
477     ok(typeof(f) === "function", "typeof(f) = " + typeof(f));
478 })(1);
480 for(var iter in "test")
481     ok(false, "unexpected forin call, test = " + iter);
483 for(var iter in null)
484     ok(false, "unexpected forin call, test = " + iter);
486 for(var iter in false)
487     ok(false, "unexpected forin call, test = " + iter);
489 for(var iter in pureDisp)
490     ok(false, "unexpected forin call in pureDisp object");
492 tmp = new Object();
493 ok(!tmp.nonexistent, "!tmp.nonexistent = " + !tmp.nonexistent);
494 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '!' expression")
496 tmp = new Object();
497 ok((~tmp.nonexistent) === -1, "!tmp.nonexistent = " + ~tmp.nonexistent);
498 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '~' expression")
500 tmp = new Object();
501 ok(isNaN(+tmp.nonexistent), "!tmp.nonexistent = " + (+tmp.nonexistent));
502 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '+' expression")
504 tmp = new Object();
505 tmp[tmp.nonexistent];
506 ok(!("nonexistent" in tmp), "nonexistent is in tmp after array expression")
508 tmp = 0;
509 if(true)
510     tmp = 1;
511 else
512     ok(false, "else evaluated");
513 ok(tmp === 1, "tmp !== 1, if not evaluated?");
515 tmp = 0;
516 if(1 === 0)
517     ok(false, "if evaluated");
518 else
519     tmp = 1;
520 ok(tmp === 1, "tmp !== 1, if not evaluated?");
522 if(false)
523     ok(false, "if(false) evaluated");
525 tmp = 0;
526 if(true)
527     tmp = 1;
528 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
530 if(false) {
531 }else {
534 var obj3 = { prop1: 1,  prop2: typeof(false) };
535 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
536 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
537 ok(obj3.constructor === Object, "unexpected obj3.constructor");
539 if(invokeVersion >= 2) {
540     eval("tmp = {prop: 'value',}");
541     ok(tmp.prop === "value", "tmp.prop = " + tmp.prop);
542     eval("tmp = {prop: 'value',second:2,}");
543     ok(tmp.prop === "value", "tmp.prop = " + tmp.prop);
544 }else {
545     try {
546         eval("tmp = {prop: 'value',}");
547     }catch(e) {
548         tmp = true;
549     }
550     ok(tmp === true, "exception not fired");
554     var blockVar = 1;
555     blockVar = 2;
557 ok(blockVar === 2, "blockVar !== 2");
559 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
560 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
562 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
563 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
564 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
565 ok(getVT(0.5) === "VT_R8", "getVT(0.5) is not VT_R8");
566 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
567 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
568 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
570 tmp = 2+2;
571 ok(tmp === 4, "2+2 !== 4");
572 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
574 tmp = 2+2.5;
575 ok(tmp === 4.5, "2+2.5 !== 4.5");
576 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
578 tmp = 1.5+2.5;
579 ok(tmp === 4, "1.4+2.5 !== 4");
580 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
582 tmp = 4-2;
583 ok(tmp === 2, "4-2 !== 2");
584 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
586 tmp = 4.5-2;
587 ok(tmp === 2.5, "4.5-2 !== 2.5");
588 ok(getVT(tmp) === "VT_R8", "getVT(4.5-2) !== VT_R8");
590 tmp = -2;
591 ok(tmp === 0-2, "-2 !== 0-2");
592 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
594 tmp = 2*3;
595 ok(tmp === 6, "2*3 !== 6");
596 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
598 tmp = 2*3.5;
599 ok(tmp === 7, "2*3.5 !== 7");
600 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
602 tmp = 2.5*3.5;
603 /* FIXME: the parser loses precision */
604 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
605 ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
606 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
608 tmp = 2*.5;
609 ok(tmp === 1, "2*.5 !== 1");
610 ok(getVT(tmp) == "VT_I4", "getVT(2*.5) !== VT_I4");
612 tmp = 4/2;
613 ok(tmp === 2, "4/2 !== 2");
614 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
616 tmp = 4.5/1.5;
617 ok(tmp === 3, "4.5/1.5 !== 3");
618 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
620 tmp = 3/2;
621 ok(tmp === 1.5, "3/2 !== 1.5");
622 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
624 tmp = 3%2;
625 ok(tmp === 1, "3%2 = " + tmp);
627 tmp = 4%2;
628 ok(tmp ===0, "4%2 = " + tmp);
630 tmp = 3.5%1.5;
631 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
633 tmp = 3%true;
634 ok(tmp === 0, "3%true = " + tmp);
636 tmp = "ab" + "cd";
637 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
639 tmp = 1;
640 ok((tmp += 1) === 2, "tmp += 1 !== 2");
641 ok(tmp === 2, "tmp !== 2");
643 tmp = 2;
644 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
645 ok(tmp === 1, "tmp !=== 1");
647 tmp = 2;
648 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
649 ok(tmp === 3, "tmp !=== 3");
651 tmp = 5;
652 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
653 ok(tmp === 2.5, "tmp !=== 2.5");
655 tmp = 3;
656 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
657 ok(tmp === 1, "tmp !== 1");
659 tmp = 8;
660 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
662 tmp = 8;
663 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
665 tmp = 8;
666 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
668 tmp = 3 || ok(false, "second or expression called");
669 ok(tmp === 3, "3 || (...) is not 3");
671 tmp = false || 2;
672 ok(tmp === 2, "false || 2 is not 2");
674 tmp = 0 && ok(false, "second and expression called");
675 ok(tmp === 0, "0 && (...) is not 0");
677 tmp = true && "test";
678 ok(tmp === "test", "true && \"test\" is not \"test\"");
680 tmp = true && 0;
681 ok(tmp === 0, "true && 0 is not 0");
683 tmp = 3 | 4;
684 ok(tmp === 7, "3 | 4 !== 7");
685 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
687 tmp = 3.5 | 0;
688 ok(tmp === 3, "3.5 | 0 !== 3");
689 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
691 tmp = -3.5 | 0;
692 ok(tmp === -3, "-3.5 | 0 !== -3");
693 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
695 tmp = 0 | NaN;
696 ok(tmp === 0, "0 | NaN = " + tmp);
698 tmp = 0 | Infinity;
699 ok(tmp === 0, "0 | NaN = " + tmp);
701 tmp = 0 | (-Infinity);
702 ok(tmp === 0, "0 | NaN = " + tmp);
704 tmp = 10;
705 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
706 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
708 tmp = (123 * Math.pow(2,32) + 2) | 0;
709 ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);
711 tmp = (-123 * Math.pow(2,32) + 2) | 0;
712 ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);
714 tmp = 3 & 5;
715 ok(tmp === 1, "3 & 5 !== 1");
716 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
718 tmp = 3.5 & 0xffff;
719 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
720 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
722 tmp = (-3.5) & 0xffffffff;
723 ok(tmp === -3, "-3.5 & 0xffff !== -3");
724 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
726 tmp = 2 << 3;
727 ok(tmp === 16, "2 << 3 = " + tmp);
729 tmp = 2 << 35;
730 ok(tmp === 16, "2 << 35 = " + tmp);
732 tmp = 8 >> 2;
733 ok(tmp === 2, "8 >> 2 = " + tmp);
735 tmp = -64 >> 4;
736 ok(tmp === -4, "-64 >> 4 = " + tmp);
738 tmp = 8 >>> 2;
739 ok(tmp === 2, "8 >> 2 = " + tmp);
741 tmp = -64 >>> 4;
742 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
744 tmp = 4 >>> NaN;
745 ok(tmp === 4, "4 >>> NaN = " + tmp);
747 tmp = 10;
748 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
749 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
751 tmp = 0xf0f0^0xff00;
752 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
753 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
755 tmp = 5;
756 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
757 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
759 tmp = ~1;
760 ok(tmp === -2, "~1 !== -2");
761 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
763 ok((3,4) === 4, "(3,4) !== 4");
765 ok(+3 === 3, "+3 !== 3");
766 ok(+true === 1, "+true !== 1");
767 ok(+false === 0, "+false !== 0");
768 ok(+null === 0, "+null !== 0");
769 ok(+"0" === 0, "+'0' !== 0");
770 ok(+"3" === 3, "+'3' !== 3");
771 ok(+"-3" === -3, "+'-3' !== -3");
772 ok(+"0xff" === 255, "+'0xff' !== 255");
773 ok(+"3e3" === 3000, "+'3e3' !== 3000");
775 tmp = new Number(1);
776 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
777 ok(tmp.constructor === Number, "unexpected tmp.constructor");
778 tmp = new String("1");
779 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
780 ok(tmp.constructor === String, "unexpected tmp.constructor");
782 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
783 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
784 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
785 ok("" + null === "null", "\"\" + null !== \"null\"");
786 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
787 ok("" + true === "true", "\"\" + true !== \"true\"");
788 ok("" + false === "false", "\"\" + false !== \"false\"");
789 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
790 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
792 ok(1 < 3.4, "1 < 3.4 failed");
793 ok(!(3.4 < 1), "3.4 < 1");
794 ok("abc" < "abcd", "abc < abcd failed");
795 ok("abcd" < "abce", "abce < abce failed");
796 ok("" < "x", "\"\" < \"x\" failed");
797 ok(!(0 < 0), "0 < 0");
799 ok(1 <= 3.4, "1 <= 3.4 failed");
800 ok(!(3.4 <= 1), "3.4 <= 1");
801 ok("abc" <= "abcd", "abc <= abcd failed");
802 ok("abcd" <= "abce", "abce <= abce failed");
803 ok("" <= "x", "\"\" <= \"x\" failed");
804 ok(0 <= 0, "0 <= 0 failed");
806 ok(3.4 > 1, "3.4 > 1 failed");
807 ok(!(1 > 3.4), "1 > 3.4");
808 ok("abcd" > "abc", "abc > abcd failed");
809 ok("abce" > "abcd", "abce > abce failed");
810 ok("x" > "", "\"x\" > \"\" failed");
811 ok(!(0 > 0), "0 > 0");
813 ok(3.4 >= 1, "3.4 >= 1 failed");
814 ok(!(1 >= 3.4), "1 >= 3.4");
815 ok("abcd" >= "abc", "abc >= abcd failed");
816 ok("abce" >= "abcd", "abce >= abce failed");
817 ok("x" >= "", "\"x\" >= \"\" failed");
818 ok(0 >= 0, "0 >= 0");
820 tmp = 1;
821 ok(++tmp === 2, "++tmp (1) is not 2");
822 ok(tmp === 2, "incremented tmp is not 2");
823 ok(--tmp === 1, "--tmp (2) is not 1");
824 ok(tmp === 1, "decremented tmp is not 1");
825 ok(tmp++ === 1, "tmp++ (1) is not 1");
826 ok(tmp === 2, "incremented tmp(1) is not 2");
827 ok(tmp-- === 2, "tmp-- (2) is not 2");
828 ok(tmp === 1, "decremented tmp is not 1");
830 tmp = new Object();
831 tmp.iii++;
832 ok(isNaN(tmp.iii), "tmp.iii = " + tmp.iii);
834 String.prototype.test = true;
835 ok("".test === true, "\"\".test is not true");
837 Boolean.prototype.test = true;
838 ok(true.test === true, "true.test is not true");
840 Number.prototype.test = true;
841 ok((0).test === true, "(0).test is not true");
842 ok((0.5).test === true, "(0.5).test is not true");
844 var state = "";
845 try {
846     ok(state === "", "try: state = " + state);
847     state = "try";
848 }catch(ex) {
849     ok(false, "unexpected catch");
851 ok(state === "try", "state = " + state + " expected try");
853 state = "";
854 try {
855     ok(state === "", "try: state = " + state);
856     state = "try";
857 }finally {
858     ok(state === "try", "finally: state = " + state);
859     state = "finally";
861 ok(state === "finally", "state = " + state + " expected finally");
863 state = "";
864 try {
865     try {
866         throw 0;
867     }finally {
868         state = "finally";
869     }
870 }catch(e) {
871     ok(state === "finally", "state = " + state + " expected finally");
872     state = "catch";
874 ok(state === "catch", "state = " + state + " expected catch");
876 try {
877     try {
878         throw 0;
879     }finally {
880         throw 1;
881     }
882 }catch(e) {
883     ok(e === 1, "e = " + e);
886 state = "";
887 try {
888     ok(state === "", "try: state = " + state);
889     state = "try";
890 }catch(ex) {
891     ok(false, "unexpected catch");
892 }finally {
893     ok(state === "try", "finally: state = " + state);
894     state = "finally";
896 ok(state === "finally", "state = " + state + " expected finally");
898 var state = "";
899 try {
900     ok(state === "", "try: state = " + state);
901     state = "try";
902     throw "except";
903 }catch(ex) {
904     ok(state === "try", "catch: state = " + state);
905     ok(ex === "except", "ex is not \"except\"");
906     state = "catch";
908 ok(state === "catch", "state = " + state + " expected catch");
910 var state = "";
911 try {
912     ok(state === "", "try: state = " + state);
913     state = "try";
914     throw true;
915 }catch(ex) {
916     ok(state === "try", "catch: state = " + state);
917     ok(ex === true, "ex is not true");
918     state = "catch";
919 }finally {
920     ok(state === "catch", "finally: state = " + state);
921     state = "finally";
923 ok(state === "finally", "state = " + state + " expected finally");
925 var state = "";
926 try {
927     ok(state === "", "try: state = " + state);
928     state = "try";
929     try { throw true; } finally {}
930 }catch(ex) {
931     ok(state === "try", "catch: state = " + state);
932     ok(ex === true, "ex is not true");
933     state = "catch";
934 }finally {
935     ok(state === "catch", "finally: state = " + state);
936     state = "finally";
938 ok(state === "finally", "state = " + state + " expected finally");
940 var state = "";
941 try {
942     ok(state === "", "try: state = " + state);
943     state = "try";
944     try { throw "except"; } catch(ex) { throw true; }
945 }catch(ex) {
946     ok(state === "try", "catch: state = " + state);
947     ok(ex === true, "ex is not true");
948     state = "catch";
949 }finally {
950     ok(state === "catch", "finally: state = " + state);
951     state = "finally";
953 ok(state === "finally", "state = " + state + " expected finally");
955 function throwFunc(x) {
956     throw x;
959 var state = "";
960 try {
961     ok(state === "", "try: state = " + state);
962     state = "try";
963     throwFunc(true);
964 }catch(ex) {
965     ok(state === "try", "catch: state = " + state);
966     ok(ex === true, "ex is not true");
967     state = "catch";
968 }finally {
969     ok(state === "catch", "finally: state = " + state);
970     state = "finally";
972 ok(state === "finally", "state = " + state + " expected finally");
974 state = "";
975 switch(1) {
976 case "1":
977     ok(false, "unexpected case \"1\"");
978 case 1:
979     ok(state === "", "case 1: state = " + state);
980     state = "1";
981 default:
982     ok(state === "1", "default: state = " + state);
983     state = "default";
984 case false:
985     ok(state === "default", "case false: state = " + state);
986     state = "false";
988 ok(state === "false", "state = " + state);
990 state = "";
991 switch("") {
992 case "1":
993 case 1:
994     ok(false, "unexpected case 1");
995 default:
996     ok(state === "", "default: state = " + state);
997     state = "default";
998 case false:
999     ok(state === "default", "case false: state = " + state);
1000     state = "false";
1002 ok(state === "false", "state = " + state);
1004 state = "";
1005 switch(1) {
1006 case "1":
1007     ok(false, "unexpected case \"1\"");
1008 case 1:
1009     ok(state === "", "case 1: state = " + state);
1010     state = "1";
1011 default:
1012     ok(state === "1", "default: state = " + state);
1013     state = "default";
1014     break;
1015 case false:
1016     ok(false, "unexpected case false");
1018 ok(state === "default", "state = " + state);
1020 switch(1) {
1021 case 2:
1022     ok(false, "unexpected case 2");
1023 case 3:
1024     ok(false, "unexpected case 3");
1027 switch(1) {
1028 case 2:
1029     ok(false, "unexpected case 2");
1030     break;
1031 default:
1032     /* empty default */
1035 switch(2) {
1036 default:
1037     ok(false, "unexpected default");
1038     break;
1039 case 2:
1040     /* empty case */
1043 switch(2) {
1044 default:
1045     ok(false, "unexpected default");
1046     break;
1047 case 1:
1048 case 2:
1049 case 3:
1050     /* empty case */
1053 (function() {
1054     var i=0;
1056     switch(1) {
1057     case 1:
1058         i++;
1059     }
1060     return i;
1061 })();
1063 (function() {
1064     var ret, x;
1066     function unreachable() {
1067         ok(false, "unreachable");
1068     }
1070     function expect(value, expect_value) {
1071         ok(value === expect_value, "got " + value + " expected " + expect_value);
1072     }
1074     ret = (function() {
1075         try {
1076             return "try";
1077             unreachable();
1078         }catch(e) {
1079             unreachable();
1080         }finally {
1081             return "finally";
1082             unreachable();
1083         }
1084         unreachable();
1085     })();
1086     expect(ret, "finally");
1088     x = "";
1089     ret = (function() {
1090         try {
1091             x += "try,";
1092             return x;
1093             unreachable();
1094         }catch(e) {
1095             unreachable();
1096         }finally {
1097             x += "finally,";
1098         }
1099         unreachable();
1100     })();
1101     expect(ret, "try,");
1102     expect(x, "try,finally,");
1104     x = "";
1105     ret = (function() {
1106         try {
1107             x += "try,"
1108             throw 1;
1109             unreachable();
1110         }catch(e) {
1111             x += "catch,";
1112             return "catch";
1113             unreachable();
1114         }finally {
1115             x += "finally,";
1116             return "finally";
1117             unreachable();
1118         }
1119         unreachable();
1120     })();
1121     expect(ret, "finally");
1122     expect(x, "try,catch,finally,");
1124     x = "";
1125     ret = (function() {
1126         try {
1127             x += "try,"
1128             throw 1;
1129             unreachable();
1130         }catch(e) {
1131             x += "catch,";
1132             return "catch";
1133             unreachable();
1134         }finally {
1135             x += "finally,";
1136         }
1137         unreachable();
1138     })();
1139     expect(ret, "catch");
1140     expect(x, "try,catch,finally,");
1142     x = "";
1143     ret = (function() {
1144         try {
1145             x += "try,"
1146             try {
1147                 x += "try2,";
1148                 return "try2";
1149             }catch(e) {
1150                 unreachable();
1151             }finally {
1152                 x += "finally2,";
1153             }
1154             unreachable();
1155         }catch(e) {
1156             unreachable();
1157         }finally {
1158             x += "finally,";
1159         }
1160         unreachable();
1161     })();
1162     expect(ret, "try2");
1163     expect(x, "try,try2,finally2,finally,");
1165     x = "";
1166     ret = (function() {
1167         while(true) {
1168             try {
1169                 x += "try,"
1170                 try {
1171                     x += "try2,";
1172                     break;
1173                 }catch(e) {
1174                     unreachable();
1175                 }finally {
1176                     x += "finally2,";
1177                 }
1178                 unreachable();
1179             }catch(e) {
1180                 unreachable();
1181             }finally {
1182                 x += "finally,";
1183             }
1184             unreachable();
1185         }
1186         x += "ret";
1187         return "ret";
1188     })();
1189     expect(ret, "ret");
1190     expect(x, "try,try2,finally2,finally,ret");
1192     x = "";
1193     ret = (function() {
1194         while(true) {
1195             try {
1196                 x += "try,"
1197                 try {
1198                     x += "try2,";
1199                     continue;
1200                 }catch(e) {
1201                     unreachable();
1202                 }finally {
1203                     x += "finally2,";
1204                 }
1205                 unreachable();
1206             }catch(e) {
1207                 unreachable();
1208             }finally {
1209                 x += "finally,";
1210                 break;
1211             }
1212             unreachable();
1213         }
1214         x += "ret";
1215         return "ret";
1216     })();
1217     expect(ret, "ret");
1218     expect(x, "try,try2,finally2,finally,ret");
1220     ret = (function() {
1221         try {
1222             return "try";
1223             unreachable();
1224         }catch(e) {
1225             unreachable();
1226         }finally {
1227             new Object();
1228             var tmp = (function() {
1229                 var s = new String();
1230                 try {
1231                     s.length;
1232                 }finally {
1233                     return 1;
1234                 }
1235             })();
1236         }
1237         unreachable();
1238     })();
1239     expect(ret, "try");
1240 })();
1242 (function() {
1243     var e;
1244     var E_FAIL = -2147467259;
1245     var JS_E_SUBSCRIPT_OUT_OF_RANGE = -2146828279;
1247     try {
1248         throwInt(E_FAIL);
1249     }catch(ex) {
1250         e = ex;
1251     }
1252     ok(e.name === "Error", "e.name = " + e.name);
1253     ok(e.message === "", "e.message = " + e.message);
1254     ok(e.number === E_FAIL, "e.number = " + e.number);
1256     try {
1257         throwInt(JS_E_SUBSCRIPT_OUT_OF_RANGE);
1258     }catch(ex) {
1259         e = ex;
1260     }
1261     ok(e.name === "RangeError", "e.name = " + e.name);
1262     ok(e.number === JS_E_SUBSCRIPT_OUT_OF_RANGE, "e.number = " + e.number);
1264     try {
1265         throwEI(JS_E_SUBSCRIPT_OUT_OF_RANGE);
1266     }catch(ex) {
1267         e = ex;
1268     }
1269     ok(e.name === "RangeError", "e.name = " + e.name);
1270     ok(e.number === JS_E_SUBSCRIPT_OUT_OF_RANGE, "e.number = " + e.number);
1271 })();
1273 tmp = eval("1");
1274 ok(tmp === 1, "eval(\"1\") !== 1");
1275 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
1276 ok(tmp === 2, "tmp !== 2");
1278 ok(eval(false) === false, "eval(false) !== false");
1279 ok(eval() === undefined, "eval() !== undefined");
1281 tmp = eval("1", "2");
1282 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
1284 var state = "";
1285 try {
1286     ok(state === "", "try: state = " + state);
1287     state = "try";
1288     eval("throwFunc(true);");
1289 }catch(ex) {
1290     ok(state === "try", "catch: state = " + state);
1291     ok(ex === true, "ex is not true");
1292     state = "catch";
1293 }finally {
1294     ok(state === "catch", "finally: state = " + state);
1295     state = "finally";
1297 ok(state === "finally", "state = " + state + " expected finally");
1299 tmp = [,,1,2,,,true];
1300 ok(tmp.length === 7, "tmp.length !== 7");
1301 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
1302 ok(tmp["3"] === 2, "tmp[3] !== 2");
1303 ok(tmp["6"] === true, "tmp[6] !== true");
1304 ok(tmp[2] === 1, "tmp[2] !== 1");
1305 ok(!("0" in tmp), "0 found in array");
1306 ok(!("1" in tmp), "1 found in array");
1307 ok("2" in tmp, "2 not found in array");
1308 ok(!("2" in [1,,,,]), "2 found in [1,,,,]");
1310 ok([1,].length === 2, "[1,].length !== 2");
1311 ok([,,].length === 3, "[,,].length !== 3");
1312 ok([,].length === 2, "[].length != 2");
1313 ok([].length === 0, "[].length != 0");
1315 tmp = 0;
1316 while(tmp < 4) {
1317     ok(tmp < 4, "tmp >= 4");
1318     tmp++;
1320 ok(tmp === 4, "tmp !== 4");
1322 tmp = 0;
1323 while(true) {
1324     ok(tmp < 4, "tmp >= 4");
1325     tmp++;
1326     if(tmp === 4) {
1327         break;
1328         ok(false, "break did not break");
1329     }
1331 ok(tmp === 4, "tmp !== 4");
1333 tmp = 0;
1334 do {
1335     ok(tmp < 4, "tmp >= 4");
1336     tmp++;
1337 } while(tmp < 4);
1338 ok(tmp === 4, "tmp !== 4");
1340 tmp = 0;
1341 do {
1342     ok(tmp === 0, "tmp !=== 0");
1343     tmp++;
1344 } while(false);
1345 ok(tmp === 1, "tmp !== 1");
1347 tmp = 0;
1348 do {
1349     ok(tmp < 4, "tmp >= 4");
1350     tmp++;
1351 } while(tmp < 4)
1352 ok(tmp === 4, "tmp !== 4")
1354 tmp = 0;
1355 while(tmp < 4) {
1356     tmp++;
1357     if(tmp === 2) {
1358         continue;
1359         ok(false, "break did not break");
1360     }
1361     ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
1363 ok(tmp === 4, "tmp !== 4");
1365 for(tmp=0; tmp < 4; tmp++)
1366     ok(tmp < 4, "tmp = " + tmp);
1367 ok(tmp === 4, "tmp !== 4");
1369 for(tmp=0; tmp < 4; tmp++) {
1370     if(tmp === 2)
1371         break;
1372     ok(tmp < 2, "tmp = " + tmp);
1374 ok(tmp === 2, "tmp !== 2");
1376 for(tmp=0; tmp < 4; tmp++) {
1377     if(tmp === 2)
1378         continue;
1379     ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
1381 ok(tmp === 4, "tmp !== 4");
1383 for(var fi=0; fi < 4; fi++)
1384     ok(fi < 4, "fi = " + fi);
1385 ok(fi === 4, "fi !== 4");
1387 tmp = true;
1388 obj1 = new Object();
1389 for(obj1.nonexistent; tmp; tmp = false)
1390     ok(!("nonexistent" in obj1), "nonexistent added to obj1");
1392 obj1 = new Object();
1393 for(tmp in obj1.nonexistent)
1394     ok(false, "for(tmp in obj1.nonexistent) called with tmp = " + tmp);
1395 ok(!("nonexistent" in obj1), "nonexistent added to obj1 by for..in loop");
1398 var i, j;
1400 /* Previous versions have broken finally block implementation */
1401 if(ScriptEngineMinorVersion() >= 8) {
1402     tmp = "";
1403     i = 0;
1404     while(true) {
1405         tmp += "1";
1406         for(i = 1; i < 3; i++) {
1407             switch(i) {
1408             case 1:
1409                 tmp += "2";
1410                 continue;
1411             case 2:
1412                 tmp += "3";
1413                 try {
1414                     throw null;
1415                 }finally {
1416                     tmp += "4";
1417                     break;
1418                 }
1419             default:
1420                 ok(false, "unexpected state");
1421             }
1422             tmp += "5";
1423         }
1424         with({prop: "6"}) {
1425             tmp += prop;
1426             break;
1427         }
1428     }
1429     ok(tmp === "123456", "tmp = " + tmp);
1432 tmp = "";
1433 i = 0;
1434 for(j in [1,2,3]) {
1435     tmp += "1";
1436     for(;;) {
1437         with({prop: "2"}) {
1438             tmp += prop;
1439             try {
1440                 throw "3";
1441             }catch(e) {
1442                 tmp += e;
1443                 with([0])
1444                     break;
1445             }
1446         }
1447         ok(false, "unexpected state");
1448     }
1449     while(true) {
1450         tmp += "4";
1451         break;
1452     }
1453     break;
1455 ok(tmp === "1234", "tmp = " + tmp);
1457 tmp = 0;
1458 for(var iter in [1,2,3]) {
1459     tmp += +iter;
1460     continue;
1462 ok(tmp === 3, "tmp = " + tmp);
1464 tmp = false;
1465 for(var iter in [1,2,3]) {
1466     switch(+iter) {
1467     case 1:
1468         tmp = true;
1469         try {
1470             continue;
1471         }finally {}
1472     default:
1473         continue;
1474     }
1476 ok(tmp, "tmp = " + tmp);
1478 loop_label:
1479 while(true) {
1480     while(true)
1481         break loop_label;
1484 loop_label: {
1485     tmp = 0;
1486     while(true) {
1487         while(true)
1488             break loop_label;
1489     }
1490     ok(false, "unexpected evaluation 1");
1493 while(true) {
1494     some_label: break;
1495     ok(false, "unexpected evaluation 2");
1498 just_label: tmp = 1;
1499 ok(tmp === 1, "tmp != 1");
1501 some_label: break some_label;
1503 other_label: {
1504     break other_label;
1505     ok(false, "unexpected evaluation 3");
1508 loop_label:
1509 do {
1510     while(true)
1511         continue loop_label;
1512 }while(false);
1514 loop_label:
1515 for(i = 0; i < 3; i++) {
1516     while(true)
1517         continue loop_label;
1520 loop_label:
1521 other_label:
1522 for(i = 0; i < 3; i++) {
1523     while(true)
1524         continue loop_label;
1527 loop_label:
1528 for(tmp in {prop: false}) {
1529     while(true)
1530         continue loop_label;
1533 ok((void 1) === undefined, "(void 1) !== undefined");
1535 var inobj = new Object();
1537 for(var iter in inobj)
1538     ok(false, "unexpected iter = " + iter);
1540 inobj.test = true;
1541 tmp = 0;
1542 for(iter in inobj) {
1543     ok(iter == "test", "unexpected iter = " + iter);
1544     tmp++;
1546 ok(tmp === 1, "for..in tmp = " + tmp);
1548 function forinTestObj() {}
1550 forinTestObj.prototype.test3 = true;
1552 var arr = new Array();
1553 inobj = new forinTestObj();
1554 inobj.test1 = true;
1555 inobj.test2 = true;
1557 tmp = 0;
1558 for(iter in inobj) {
1559     arr[iter] = true;
1560     tmp++;
1563 ok(tmp === 3, "for..in tmp = " + tmp);
1564 ok(arr["test1"] === true, "arr[test1] !== true");
1565 ok(arr["test2"] === true, "arr[test2] !== true");
1566 ok(arr["test3"] === true, "arr[test3] !== true");
1568 tmp = new Object();
1569 tmp.test = false;
1570 ok((delete tmp.test) === true, "delete returned false");
1571 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1572 ok(!("test" in tmp), "test is still in tmp after delete?");
1573 for(iter in tmp)
1574     ok(false, "tmp has prop " + iter);
1575 ok((delete tmp.test) === true, "deleting test didn't return true");
1576 ok((delete tmp.nonexistent) === true, "deleting nonexistent didn't return true");
1577 ok((delete nonexistent) === true, "deleting nonexistent didn't return true");
1579 tmp = new Object();
1580 tmp.test = false;
1581 ok((delete tmp["test"]) === true, "delete returned false");
1582 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1583 ok(!("test" in tmp), "test is still in tmp after delete?");
1585 tmp.testWith = true;
1586 with(tmp)
1587     ok(testWith === true, "testWith !== true");
1589 if(false) {
1590     var varTest1 = true;
1593 ok(varTest1 === undefined, "varTest1 = " + varTest1);
1594 ok(varTest2 === undefined, "varTest2 = " + varTest1);
1596 var varTest2;
1598 function varTestFunc(varTest3) {
1599     var varTest3;
1601     ok(varTest3 === 3, "varTest3 = " + varTest3);
1602     ok(varTest4 === undefined, "varTest4 = " + varTest4);
1604     var varTest4;
1607 varTestFunc(3);
1609 deleteTest = 1;
1610 delete deleteTest;
1611 try {
1612     tmp = deleteTest;
1613     ok(false, "deleteTest did not throw an exception?");
1614 }catch(ex) {}
1616 (function() {
1617     var to_delete = 2;
1618     var r = delete to_delete;
1619     ok(r === false, "delete 1 returned " + r);
1620     if(r)
1621         return;
1622     ok(to_delete === 2, "to_delete = " + to_delete);
1624     to_delete = new Object();
1625     r = delete to_delete;
1626     ok(r === false, "delete 2 returned " + r);
1627     ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
1628 })();
1630 (function(to_delete) {
1631     var r = delete to_delete;
1632     ok(r === false, "delete 3 returned " + r);
1633     ok(to_delete === 2, "to_delete = " + to_delete);
1635     to_delete = new Object();
1636     r = delete to_delete;
1637     ok(r === false, "delete 4 returned " + r);
1638     ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
1639 })(2);
1641 (function() {
1642     with({to_delete: new Object()}) {
1643         var r = delete to_delete;
1644         ok(r === true, "delete returned " + r);
1645     }
1646 })();
1648 if (false)
1649     if (true)
1650         ok(false, "if evaluated");
1651     else
1652         ok(false, "else should be associated with nearest if statement");
1654 if (true)
1655     if (false)
1656         ok(false, "if evaluated");
1657     else
1658         ok(true, "else should be associated with nearest if statement");
1660 function instanceOfTest() {}
1661 tmp = new instanceOfTest();
1663 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
1664 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1665 ok((tmp instanceof String) === false, "tmp is instance of String");
1667 instanceOfTest.prototype = new Object();
1668 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
1669 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1671 ok((1 instanceof Object) === false, "1 is instance of Object");
1672 ok((false instanceof Boolean) === false, "false is instance of Boolean");
1673 ok(("" instanceof Object) === false, "'' is instance of Object");
1675 (function () {
1676     ok((arguments instanceof Object) === true, "argument is not instance of Object");
1677     ok((arguments instanceof Array) === false, "argument is not instance of Array");
1678     ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
1679 })(1,2);
1681 obj = new String();
1682 ok(("length" in obj) === true, "length is not in obj");
1683 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
1684 ok(("abc" in obj) === false, "test is in obj");
1685 obj.abc = 1;
1686 ok(("abc" in obj) === true, "test is not in obj");
1687 ok(("1" in obj) === false, "1 is in obj");
1689 obj = [1,2,3];
1690 ok((1 in obj) === true, "1 is not in obj");
1692 obj = new Object();
1693 try {
1694     obj.prop["test"];
1695     ok(false, "expected exception");
1696 }catch(e) {}
1697 ok(!("prop" in obj), "prop in obj");
1699 if(invokeVersion >= 2) {
1700     ok("test"[0] === "t", '"test"[0] = ' + test[0]);
1701     ok("test"[5] === undefined, '"test"[0] = ' + test[0]);
1703     tmp = "test";
1704     ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1705     tmp[1] = "x";
1706     ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1707     ok(tmp["1"] === "e", "tmp['1'] = " + tmp["1"]);
1708     ok(tmp["0x1"] === undefined, "tmp['0x1'] = " + tmp["0x1"]);
1709 }else {
1710     ok("test"[0] === undefined, '"test"[0] = ' + test[0]);
1713 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
1714 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
1715 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
1716 ok(isNaN() === true, "isNaN() !== true");
1717 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
1718 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
1719 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
1721 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
1722 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
1723 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
1724 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
1725 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
1726 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
1727 ok(isFinite() === false, "isFinite() !== false");
1729 ok((1 < NaN) === false, "(1 < NaN) !== false");
1730 ok((1 > NaN) === false, "(1 > NaN) !== false");
1731 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
1732 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
1733 ok((NaN < 1) === false, "(NaN < 1) !== false");
1734 ok((NaN > 1) === false, "(NaN > 1) !== false");
1735 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
1736 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
1737 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
1738 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
1739 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
1741 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
1742 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
1743 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
1744 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
1745 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
1746 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
1748 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
1749 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
1750 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1751 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1752 ok((0 === NaN) === false, "(0 === NaN) !== false");
1754 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
1755 ok((NaN == NaN) === false, "(NaN === NaN) != false");
1756 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1757 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1758 ok((0 == NaN) === false, "(0 === NaN) != false");
1760 // escape tests
1761 var escapeTests = [
1762     ["\'", "\\'", 39],
1763     ["\"", "\\\"", 34],
1764     ["\\", "\\\\", 92],
1765     ["\b", "\\b", 8],
1766     ["\t", "\\t", 9],
1767     ["\n", "\\n", 10],
1768     ["\v", "\\v", 118],
1769     ["\f", "\\f", 12],
1770     ["\r", "\\r", 13],
1771     ["\xf3", "\\xf3", 0xf3],
1772     ["\u1234", "\\u1234", 0x1234],
1773     ["\a", "\\a", 97],
1774     ["\?", "\\?", 63]
1777 for(i=0; i<escapeTests.length; i++) {
1778     tmp = escapeTests[i][0].charCodeAt(0);
1779     ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]);
1782 tmp = !+"\v1";
1783 ok(tmp === true, '!+"\v1" = ' + tmp);
1785 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
1786 tmp = testFunc2(1);
1787 ok(tmp === 2, "testFunc2(1) = " + tmp);
1788 function testFunc2(x) { return x+1; }
1790 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
1791 tmp = testFunc3(1);
1792 ok(tmp === 3, "testFunc3(1) = " + tmp);
1793 tmp = function testFunc3(x) { return x+2; };
1795 tmp = testFunc4(1);
1796 ok(tmp === 5, "testFunc4(1) = " + tmp);
1797 tmp = function testFunc4(x) { return x+3; };
1798 tmp = testFunc4(1);
1799 testFunc4 = 1;
1800 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1801 ok(tmp === 5, "testFunc4(1) = " + tmp);
1802 tmp = function testFunc4(x) { return x+4; };
1803 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1805 function testEmbeddedFunctions() {
1806     ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
1807     tmp = testFunc5(1);
1808     ok(tmp === 3, "testFunc5(1) = " + tmp);
1809     tmp = function testFunc5(x) { return x+2; };
1811     tmp = testFunc6(1);
1812     ok(tmp === 5, "testFunc6(1) = " + tmp);
1813     tmp = function testFunc6(x) { return x+3; };
1814     tmp = testFunc6(1);
1815     ok(tmp === 5, "testFunc6(1) = " + tmp);
1816     tmp = function testFunc6(x) { return x+4; };
1817     testFunc6 = 1;
1818     ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
1821 testEmbeddedFunctions();
1823 date = new Date();
1824 date.toString = function() { return "toString"; }
1825 ok(""+date === "toString", "''+date = " + date);
1826 date.toString = function() { return this; }
1827 ok(""+date === ""+date.valueOf(), "''+date = " + date);
1829 str = new String("test");
1830 str.valueOf = function() { return "valueOf"; }
1831 ok(""+str === "valueOf", "''+str = " + str);
1832 str.valueOf = function() { return new Date(); }
1833 ok(""+str === "test", "''+str = " + str);
1835 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
1837 var re = /=(\?|%3F)/g;
1838 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
1840 tmp = new Array();
1841 for(var i=0; i<2; i++)
1842     tmp[i] = /b/;
1843 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
1845 ok(isNullBSTR(getNullBSTR()), "isNullBSTR(getNullBSTR()) failed\n");
1846 ok(getNullBSTR() === '', "getNullBSTR() !== ''");
1847 ok(+getNullBSTR() === 0 , "+getNullBTR() !=== 0");
1849 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1850 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1851 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
1852 ok(nullDisp !== re, "nullDisp === re");
1853 ok(nullDisp === null, "nullDisp === null");
1854 ok(nullDisp == null, "nullDisp == null");
1855 ok(getVT(true && nullDisp) === "VT_DISPATCH",
1856    "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
1857 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1858 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1859 ok(nullDisp != new Object(), "nullDisp == new Object()");
1860 ok(new Object() != nullDisp, "new Object() == nullDisp");
1861 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1862 tmp = getVT(Object(nullDisp));
1863 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1864 tmp = Object(nullDisp).toString();
1865 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1867 function do_test() {}
1868 function nosemicolon() {} nosemicolon();
1869 function () {} nosemicolon();
1871 if(false) {
1872     function in_if_false() { return true; } ok(false, "!?");
1875 ok(in_if_false(), "in_if_false failed");
1877 (function() { newValue = 1; })();
1878 ok(newValue === 1, "newValue = " + newValue);
1880 obj = {undefined: 3};
1882 ok(typeof(name_override_func) === "function", "typeof(name_override_func) = " + typeof(name_override_func));
1883 name_override_func = 3;
1884 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1885 function name_override_func() {};
1886 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1888 tmp = (function() {
1889     var ret = false;
1890     with({ret: true})
1891         return ret;
1892 })();
1893 ok(tmp, "tmp = " + tmp);
1895 tmp = (function() {
1896     for(var iter in [1,2,3,4]) {
1897         var ret = false;
1898         with({ret: true})
1899             return ret;
1900     }
1901 })();
1902 ok(tmp, "tmp = " + tmp);
1904 (function() {
1905     ok(typeof(func) === "function", "typeof(func)  = " + typeof(func));
1906     with(new Object()) {
1907         var x = false && function func() {};
1908     }
1909     ok(typeof(func) === "function", "typeof(func)  = " + typeof(func));
1910 })();
1912 (function() {
1913     ok(x === undefined, "x = " + x); // x is declared, but never initialized
1914     with({x: 1}) {
1915         ok(x === 1, "x = " + x);
1916         var x = 2;
1917         ok(x === 2, "x = " + x);
1918     }
1919     ok(x === undefined, "x = " + x);
1920 })();
1922 var get, set;
1924 /* NoNewline rule parser tests */
1925 while(true) {
1926     if(true) break
1927     tmp = false
1930 while(true) {
1931     if(true) break /*
1932                     * no semicolon, but comment present */
1933     tmp = false
1936 while(true) {
1937     if(true) break // no semicolon, but comment present
1938     tmp = false
1941 while(true) {
1942     break
1943     continue
1944     tmp = false
1947 function returnTest() {
1948     return
1949     true;
1952 ok(returnTest() === undefined, "returnTest = " + returnTest());
1954 ActiveXObject = 1;
1955 ok(ActiveXObject === 1, "ActiveXObject = " + ActiveXObject);
1957 Boolean = 1;
1958 ok(Boolean === 1, "Boolean = " + Boolean);
1960 Object = 1;
1961 ok(Object === 1, "Object = " + Object);
1963 Array = 1;
1964 ok(Array === 1, "Array = " + Array);
1966 Date = 1;
1967 ok(Date === 1, "Date = " + Date);
1969 Error = 1;
1970 ok(Error === 1, "Error = " + Error);
1972 /* Keep this test in the end of file */
1973 undefined = 6;
1974 ok(undefined === 6, "undefined = " + undefined);
1976 NaN = 6;
1977 ok(NaN === 6, "NaN !== 6");
1979 Infinity = 6;
1980 ok(Infinity === 6, "Infinity !== 6");
1982 Math = 6;
1983 ok(Math === 6, "NaN !== 6");
1985 reportSuccess();