1/*
2 * Copyright 2008 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19var tmp;
20
21ok(true, "true is not true?");
22ok(!false, "!false is not true");
23ok(!undefined, "!undefined is not true");
24ok(!null, "!null is not true");
25ok(!0, "!0 is not true");
26ok(!0.0, "!0.0 is not true");
27
28ok(1 === 1, "1 === 1 is false");
29ok(!(1 === 2), "!(1 === 2) is false");
30ok(1.0 === 1, "1.0 === 1 is false");
31ok("abc" === "abc", "\"abc\" === \"abc\" is false");
32ok(true === true, "true === true is false");
33ok(null === null, "null === null is false");
34ok(undefined === undefined, "undefined === undefined is false");
35ok(!(undefined === null), "!(undefined === null) is false");
36ok(1E0 === 1, "1E0 === 1 is false");
37ok(1000000*1000000 === 1000000000000, "1000000*1000000 === 1000000000000 is false");
38ok(8.64e15 === 8640000000000000, "8.64e15 !== 8640000000000000");
39ok(1e2147483648 === Infinity, "1e2147483648 !== Infinity");
40
41ok(00 === 0, "00 != 0");
42ok(010 === 8, "010 != 8");
43ok(077 === 63, "077 != 63");
44ok(080 === 80, "080 != 80");
45ok(090 === 90, "090 != 90");
46ok(018 === 18, "018 != 18");
47tmp = 07777777777777777777777;
48ok(typeof(tmp) === "number" && tmp > 0xffffffff, "tmp = " + tmp);
49tmp = 07777777779777777777777;
50ok(typeof(tmp) === "number" && tmp > 0xffffffff, "tmp = " + tmp);
51ok(0xffffffff === 4294967295, "0xffffffff = " + 0xffffffff);
52tmp = 0x10000000000000000000000000000000000000000000000000000000000000000;
53ok(tmp === Math.pow(2, 256), "0x1000...00 != 2^256");
54
55ok(1 !== 2, "1 !== 2 is false");
56ok(null !== undefined, "null !== undefined is false");
57
58ok(1 == 1, "1 == 1 is false");
59ok(!(1 == 2), "!(1 == 2) is false");
60ok(1.0 == 1, "1.0 == 1 is false");
61ok("abc" == "abc", "\"abc\" == \"abc\" is false");
62ok(true == true, "true == true is false");
63ok(null == null, "null == null is false");
64ok(undefined == undefined, "undefined == undefined is false");
65ok(undefined == null, "undefined == null is false");
66ok(true == 1, "true == 1 is false");
67ok(!(true == 2), "true == 2");
68ok(0 == false, "0 == false is false");
69
70ok(1 != 2, "1 != 2 is false");
71ok(false != 1, "false != 1 is false");
72
73ok(this === test, "this !== test");
74eval('ok(this === test, "this !== test");');
75
76var trueVar = true;
77ok(trueVar, "trueVar is not true");
78
79ok(ScriptEngine.length === 0, "ScriptEngine.length is not 0");
80
81function 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);
90
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]);
96
97    ok(arguments["0x0"] === undefined, "arguments['0x0'] = " + arguments["0x0"]);
98    ok(arguments["x"] === undefined, "arguments['x'] = " + arguments["x"]);
99
100    ok(this === test, "this !== test");
101    eval('ok(this === test, "this !== test");');
102
103    tmp = delete arguments;
104    ok(tmp === false, "arguments deleted");
105    ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments));
106
107    x = 2;
108    ok(x === 2, "x = " + x);
109    ok(arguments[0] === 2, "arguments[0] = " + arguments[0]);
110
111    return true;
112}
113
114ok(testFunc1.length === 2, "testFunc1.length is not 2");
115ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
116
117ok(Object.prototype !== undefined, "Object.prototype is undefined");
118ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
119ok(String.prototype !== undefined, "String.prototype is undefined");
120ok(Array.prototype !== undefined, "Array.prototype is undefined");
121ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
122ok(Number.prototype !== undefined, "Number.prototype is undefined");
123ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
124ok(Math !== undefined, "Math is undefined");
125ok(Math.prototype === undefined, "Math.prototype is not undefined");
126ok(Function.prototype !== undefined, "Function.prototype is undefined");
127ok(Function.prototype.prototype === undefined, "Function.prototype.prototype is not undefined");
128ok(Date.prototype !== undefined, "Date.prototype is undefined");
129ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
130
131function testConstructor(constr, name, inst) {
132    ok(constr.prototype.constructor === constr, name + ".prototype.constructor !== " + name);
133    ok(constr.prototype.hasOwnProperty("constructor"), name + ".prototype.hasOwnProperty('constructor')");
134
135    if(!inst)
136        inst = new constr();
137
138    ok(inst.constructor === constr, "(new " + name + "()).constructor !== " + name);
139    ok(!inst.hasOwnProperty("constructor"), "(new " + name + "()).hasOwnProperty('constructor')");
140}
141
142testConstructor(Object, "Object");
143testConstructor(String, "String");
144testConstructor(Array, "Array");
145testConstructor(Boolean, "Boolean");
146testConstructor(Number, "Number");
147testConstructor(RegExp, "RegExp", /x/);
148testConstructor(Function, "Function");
149testConstructor(Date, "Date");
150testConstructor(VBArray, "VBArray", new VBArray(createArray()));
151testConstructor(Error, "Error");
152testConstructor(EvalError, "EvalError");
153testConstructor(RangeError, "RangeError");
154testConstructor(ReferenceError, "ReferenceError");
155testConstructor(RegExpError, "RegExpError");
156testConstructor(SyntaxError, "SyntaxError");
157testConstructor(TypeError, "TypeError");
158testConstructor(URIError, "URIError");
159
160Function.prototype.test = true;
161ok(testFunc1.test === true, "testFunc1.test !== true");
162ok(Function.test === true, "Function.test !== true");
163
164ok(typeof(0) === "number", "typeof(0) is not number");
165ok(typeof(1.5) === "number", "typeof(1.5) is not number");
166ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
167ok(typeof("") === "string", "typeof(\"\") is not string");
168ok(typeof(true) === "boolean", "typeof(true) is not boolean");
169ok(typeof(null) === "object", "typeof(null) is not object");
170ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
171ok(typeof(Math) === "object", "typeof(Math) is not object");
172ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
173ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
174ok(typeof(String) === "function", "typeof(String) is not function");
175ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
176ok(typeof(this) === "object", "typeof(this) is not object");
177ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
178tmp = typeof((new Object()).doesnotexist);
179ok(tmp === "undefined", "typeof((new Object).doesnotexist = " + tmp);
180tmp = typeof(testObj.onlyDispID);
181ok(tmp === "unknown", "typeof(testObj.onlyDispID) = " + tmp);
182
183ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
184
185ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
186
187(tmp) = 3;
188ok(tmp === 3, "tmp = " + tmp);
189
190function testRecFunc(x) {
191    ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
192    if(x) {
193        testRecFunc(false);
194        ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
195        ok(testRecFunc.arguments[0] === true, "testRecFunc.arguments.x = " + testRecFunc.arguments[0]);
196    }
197}
198
199testRecFunc.arguments = 5;
200ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
201testRecFunc(true);
202ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
203
204function argumentsTest() {
205    var save = arguments;
206    with({arguments: 1}) {
207        ok(arguments === 1, "arguments = " + arguments);
208        (function() {
209            ok(argumentsTest.arguments === save, "unexpected argumentsTest.arguments");
210        })();
211    }
212    eval('ok(arguments === save, "unexpected arguments");');
213    [1,2].sort(function() {
214        ok(argumentsTest.arguments === save, "unexpected argumentsTest.arguments");
215        return 1;
216    });
217}
218
219argumentsTest();
220
221// arguments object detached from its execution context
222(function() {
223    var args, get_x, set_x;
224
225    function test_args(detached) {
226        ok(args[0] === 1, "args[0] = " + args[0]);
227        set_x(2);
228        ok(args[0] === (detached ? 1 : 2), "args[0] = " + args[0] + " expected " + (detached ? 1 : 2));
229        args[0] = 3;
230        ok(get_x() === (detached ? 2 : 3), "get_x() = " + get_x());
231        ok(args[0] === 3, "args[0] = " + args[0]);
232    }
233
234    (function(x) {
235        args = arguments;
236        get_x = function() { return x; };
237        set_x = function(v) { x = v; };
238
239        test_args(false);
240        x = 1;
241    })(1);
242
243    test_args(true);
244})();
245
246// arguments is a regular variable, it may be overwritten
247(function() {
248    ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments));
249    arguments = 1;
250    ok(arguments === 1, "arguments = " + arguments);
251})();
252
253(function callAsExprTest() {
254    ok(callAsExprTest.arguments === null, "callAsExprTest.arguments = " + callAsExprTest.arguments);
255})(1,2);
256
257tmp = (function() {1;})();
258ok(tmp === undefined, "tmp = " + tmp);
259tmp = eval("1;");
260ok(tmp === 1, "tmp = " + tmp);
261tmp = eval("1,2;");
262ok(tmp === 2, "tmp = " + tmp);
263tmp = eval("testNoRes(),2;");
264ok(tmp === 2, "tmp = " + tmp);
265tmp = eval("if(true) {3}");
266ok(tmp === 3, "tmp = " + tmp);
267eval("testRes(); testRes()");
268tmp = eval("3; if(false) {4;} else {};;;")
269ok(tmp === 3, "tmp = " + tmp);
270tmp = eval("try { 1; } finally { 2; }")
271ok(tmp === 2, "tmp = " + tmp);
272
273testNoRes();
274testRes() && testRes();
275testNoRes(), testNoRes();
276
277(function() {
278    eval("var x=1;");
279    ok(x === 1, "x = " + x);
280})();
281
282(function() {
283    var e = eval;
284    var r = e(1);
285    ok(r === 1, "r = " + r);
286    (function(x, a) { x(a); })(eval, "2");
287})();
288
289(function(r) {
290    r = eval("1");
291    ok(r === 1, "r = " + r);
292    (function(x, a) { x(a); })(eval, "2");
293})();
294
295tmp = (function(){ return testNoRes(), testRes();})();
296
297var f1, f2;
298
299ok(funcexpr() == 2, "funcexpr() = " + funcexpr());
300
301f1 = function funcexpr() { return 1; }
302ok(f1 != funcexpr, "f1 == funcexpr");
303ok(f1() === 1, "f1() = " + f1());
304
305f2 = function funcexpr() { return 2; }
306ok(f2 != funcexpr, "f2 != funcexpr");
307ok(f2() === 2, "f2() = " + f2());
308
309f1 = null;
310for(i = 0; i < 3; i++) {
311    f2 = function funcexpr2() {};
312    ok(f1 != f2, "f1 == f2");
313    f1 = f2;
314}
315
316f1 = null;
317for(i = 0; i < 3; i++) {
318    f2 = function() {};
319    ok(f1 != f2, "f1 == f2");
320    f1 = f2;
321}
322
323(function() {
324    ok(infuncexpr() == 2, "infuncexpr() = " + infuncexpr());
325
326    f1 = function infuncexpr() { return 1; }
327    ok(f1 != funcexpr, "f1 == funcexpr");
328    ok(f1() === 1, "f1() = " + f1());
329
330    f2 = function infuncexpr() { return 2; }
331    ok(f2 != funcexpr, "f2 != funcexpr");
332    ok(f2() === 2, "f2() = " + f2());
333
334    f1 = null;
335    for(i = 0; i < 3; i++) {
336        f2 = function infuncexpr2() {};
337        ok(f1 != f2, "f1 == f2");
338        f1 = f2;
339    }
340
341    f1 = null;
342    for(i = 0; i < 3; i++) {
343        f2 = function() {};
344        ok(f1 != f2, "f1 == f2");
345        f1 = f2;
346    }
347})();
348
349var obj1 = new Object();
350ok(typeof(obj1) === "object", "typeof(obj1) is not object");
351ok(obj1.constructor === Object, "unexpected obj1.constructor");
352obj1.test = true;
353obj1.func = function () {
354    ok(this === obj1, "this is not obj1");
355    ok(this.test === true, "this.test is not true");
356    ok(arguments.length === 1, "arguments.length is not 1");
357    ok(arguments["0"] === true, "arguments[0] is not true");
358    ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
359
360    return "test";
361};
362
363ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
364
365function testConstr1() {
366    this.var1 = 1;
367
368    ok(this !== undefined, "this is undefined");
369    ok(arguments.length === 1, "arguments.length is not 1");
370    ok(arguments["0"] === true, "arguments[0] is not 1");
371    ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
372
373    return false;
374}
375
376testConstr1.prototype.pvar = 1;
377ok(testConstr1.prototype.constructor === testConstr1, "testConstr1.prototype.constructor !== testConstr1");
378
379var obj2 = new testConstr1(true);
380ok(typeof(obj2) === "object", "typeof(obj2) is not object");
381ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
382ok(obj2.pvar === 1, "obj2.pvar is not 1");
383ok(!obj2.hasOwnProperty('constructor'), "obj2.hasOwnProperty('constructor')");
384
385testConstr1.prototype.pvar = 2;
386ok(obj2.pvar === 2, "obj2.pvar is not 2");
387
388obj2.pvar = 3;
389testConstr1.prototype.pvar = 1;
390ok(obj2.pvar === 3, "obj2.pvar is not 3");
391
392obj1 = new Object();
393function testConstr3() {
394    return obj1;
395}
396
397obj2 = new testConstr3();
398ok(obj1 === obj2, "obj1 != obj2");
399
400function testConstr4() {
401    return 2;
402}
403
404obj2 = new testConstr3();
405ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
406
407var obj3 = new Object;
408ok(typeof(obj3) === "object", "typeof(obj3) is not object");
409
410(function() {
411    ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
412    function func() {}
413    ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
414    func = 0;
415    ok(typeof(func) === "number", "typeof(func) = " + typeof(func));
416})();
417
418(function(f) {
419    ok(typeof(f) === "function", "typeof(f) = " + typeof(f));
420    function f() {};
421    ok(typeof(f) === "function", "typeof(f) = " + typeof(f));
422})(1);
423
424for(var iter in "test")
425    ok(false, "unexpected forin call, test = " + iter);
426
427for(var iter in null)
428    ok(false, "unexpected forin call, test = " + iter);
429
430for(var iter in false)
431    ok(false, "unexpected forin call, test = " + iter);
432
433for(var iter in pureDisp)
434    ok(false, "unexpected forin call in pureDisp object");
435
436tmp = new Object();
437ok(!tmp.nonexistent, "!tmp.nonexistent = " + !tmp.nonexistent);
438ok(!("nonexistent" in tmp), "nonexistent is in tmp after '!' expression")
439
440tmp = new Object();
441ok((~tmp.nonexistent) === -1, "!tmp.nonexistent = " + ~tmp.nonexistent);
442ok(!("nonexistent" in tmp), "nonexistent is in tmp after '~' expression")
443
444tmp = new Object();
445ok(isNaN(+tmp.nonexistent), "!tmp.nonexistent = " + (+tmp.nonexistent));
446ok(!("nonexistent" in tmp), "nonexistent is in tmp after '+' expression")
447
448tmp = new Object();
449tmp[tmp.nonexistent];
450ok(!("nonexistent" in tmp), "nonexistent is in tmp after array expression")
451
452tmp = 0;
453if(true)
454    tmp = 1;
455else
456    ok(false, "else evaluated");
457ok(tmp === 1, "tmp !== 1, if not evaluated?");
458
459tmp = 0;
460if(1 === 0)
461    ok(false, "if evaluated");
462else
463    tmp = 1;
464ok(tmp === 1, "tmp !== 1, if not evaluated?");
465
466if(false)
467    ok(false, "if(false) evaluated");
468
469tmp = 0;
470if(true)
471    tmp = 1;
472ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
473
474if(false) {
475}else {
476}
477
478var obj3 = { prop1: 1,  prop2: typeof(false) };
479ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
480ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
481ok(obj3.constructor === Object, "unexpected obj3.constructor");
482
483{
484    var blockVar = 1;
485    blockVar = 2;
486}
487ok(blockVar === 2, "blockVar !== 2");
488
489ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
490ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
491
492ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
493ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
494ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
495ok(getVT(0.5) === "VT_R8", "getVT(0.5) is not VT_R8");
496ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
497ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
498ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
499
500tmp = 2+2;
501ok(tmp === 4, "2+2 !== 4");
502ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
503
504tmp = 2+2.5;
505ok(tmp === 4.5, "2+2.5 !== 4.5");
506ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
507
508tmp = 1.5+2.5;
509ok(tmp === 4, "1.4+2.5 !== 4");
510ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
511
512tmp = 4-2;
513ok(tmp === 2, "4-2 !== 2");
514ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
515
516tmp = 4.5-2;
517ok(tmp === 2.5, "4.5-2 !== 2.5");
518ok(getVT(tmp) === "VT_R8", "getVT(4.5-2) !== VT_R8");
519
520tmp = -2;
521ok(tmp === 0-2, "-2 !== 0-2");
522ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
523
524tmp = 2*3;
525ok(tmp === 6, "2*3 !== 6");
526ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
527
528tmp = 2*3.5;
529ok(tmp === 7, "2*3.5 !== 7");
530ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
531
532tmp = 2.5*3.5;
533/* FIXME: the parser loses precision */
534/* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
535ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
536ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
537
538tmp = 2*.5;
539ok(tmp === 1, "2*.5 !== 1");
540ok(getVT(tmp) == "VT_I4", "getVT(2*.5) !== VT_I4");
541
542tmp = 4/2;
543ok(tmp === 2, "4/2 !== 2");
544ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
545
546tmp = 4.5/1.5;
547ok(tmp === 3, "4.5/1.5 !== 3");
548ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
549
550tmp = 3/2;
551ok(tmp === 1.5, "3/2 !== 1.5");
552ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
553
554tmp = 3%2;
555ok(tmp === 1, "3%2 = " + tmp);
556
557tmp = 4%2;
558ok(tmp ===0, "4%2 = " + tmp);
559
560tmp = 3.5%1.5;
561ok(tmp === 0.5, "3.5%1.5 = " + tmp);
562
563tmp = 3%true;
564ok(tmp === 0, "3%true = " + tmp);
565
566tmp = "ab" + "cd";
567ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
568
569tmp = 1;
570ok((tmp += 1) === 2, "tmp += 1 !== 2");
571ok(tmp === 2, "tmp !== 2");
572
573tmp = 2;
574ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
575ok(tmp === 1, "tmp !=== 1");
576
577tmp = 2;
578ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
579ok(tmp === 3, "tmp !=== 3");
580
581tmp = 5;
582ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
583ok(tmp === 2.5, "tmp !=== 2.5");
584
585tmp = 3;
586ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
587ok(tmp === 1, "tmp !== 1");
588
589tmp = 8;
590ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
591
592tmp = 8;
593ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
594
595tmp = 8;
596ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
597
598tmp = 3 || ok(false, "second or expression called");
599ok(tmp === 3, "3 || (...) is not 3");
600
601tmp = false || 2;
602ok(tmp === 2, "false || 2 is not 2");
603
604tmp = 0 && ok(false, "second and expression called");
605ok(tmp === 0, "0 && (...) is not 0");
606
607tmp = true && "test";
608ok(tmp === "test", "true && \"test\" is not \"test\"");
609
610tmp = true && 0;
611ok(tmp === 0, "true && 0 is not 0");
612
613tmp = 3 | 4;
614ok(tmp === 7, "3 | 4 !== 7");
615ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
616
617tmp = 3.5 | 0;
618ok(tmp === 3, "3.5 | 0 !== 3");
619ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
620
621tmp = -3.5 | 0;
622ok(tmp === -3, "-3.5 | 0 !== -3");
623ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
624
625tmp = 0 | NaN;
626ok(tmp === 0, "0 | NaN = " + tmp);
627
628tmp = 0 | Infinity;
629ok(tmp === 0, "0 | NaN = " + tmp);
630
631tmp = 0 | (-Infinity);
632ok(tmp === 0, "0 | NaN = " + tmp);
633
634tmp = 10;
635ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
636ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
637
638tmp = (123 * Math.pow(2,32) + 2) | 0;
639ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);
640
641tmp = (-123 * Math.pow(2,32) + 2) | 0;
642ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);
643
644tmp = 3 & 5;
645ok(tmp === 1, "3 & 5 !== 1");
646ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
647
648tmp = 3.5 & 0xffff;
649ok(tmp === 3, "3.5 & 0xffff !== 3 ");
650ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
651
652tmp = (-3.5) & 0xffffffff;
653ok(tmp === -3, "-3.5 & 0xffff !== -3");
654ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
655
656tmp = 2 << 3;
657ok(tmp === 16, "2 << 3 = " + tmp);
658
659tmp = 2 << 35;
660ok(tmp === 16, "2 << 35 = " + tmp);
661
662tmp = 8 >> 2;
663ok(tmp === 2, "8 >> 2 = " + tmp);
664
665tmp = -64 >> 4;
666ok(tmp === -4, "-64 >> 4 = " + tmp);
667
668tmp = 8 >>> 2;
669ok(tmp === 2, "8 >> 2 = " + tmp);
670
671tmp = -64 >>> 4;
672ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
673
674tmp = 4 >>> NaN;
675ok(tmp === 4, "4 >>> NaN = " + tmp);
676
677tmp = 10;
678ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
679ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
680
681tmp = 0xf0f0^0xff00;
682ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
683ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
684
685tmp = 5;
686ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
687ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
688
689tmp = ~1;
690ok(tmp === -2, "~1 !== -2");
691ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
692
693ok((3,4) === 4, "(3,4) !== 4");
694
695ok(+3 === 3, "+3 !== 3");
696ok(+true === 1, "+true !== 1");
697ok(+false === 0, "+false !== 0");
698ok(+null === 0, "+null !== 0");
699ok(+"0" === 0, "+'0' !== 0");
700ok(+"3" === 3, "+'3' !== 3");
701ok(+"-3" === -3, "+'-3' !== -3");
702ok(+"0xff" === 255, "+'0xff' !== 255");
703ok(+"3e3" === 3000, "+'3e3' !== 3000");
704
705tmp = new Number(1);
706ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
707ok(tmp.constructor === Number, "unexpected tmp.constructor");
708tmp = new String("1");
709ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
710ok(tmp.constructor === String, "unexpected tmp.constructor");
711
712ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
713ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
714ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
715ok("" + null === "null", "\"\" + null !== \"null\"");
716ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
717ok("" + true === "true", "\"\" + true !== \"true\"");
718ok("" + false === "false", "\"\" + false !== \"false\"");
719ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
720ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
721
722ok(1 < 3.4, "1 < 3.4 failed");
723ok(!(3.4 < 1), "3.4 < 1");
724ok("abc" < "abcd", "abc < abcd failed");
725ok("abcd" < "abce", "abce < abce failed");
726ok("" < "x", "\"\" < \"x\" failed");
727ok(!(0 < 0), "0 < 0");
728
729ok(1 <= 3.4, "1 <= 3.4 failed");
730ok(!(3.4 <= 1), "3.4 <= 1");
731ok("abc" <= "abcd", "abc <= abcd failed");
732ok("abcd" <= "abce", "abce <= abce failed");
733ok("" <= "x", "\"\" <= \"x\" failed");
734ok(0 <= 0, "0 <= 0 failed");
735
736ok(3.4 > 1, "3.4 > 1 failed");
737ok(!(1 > 3.4), "1 > 3.4");
738ok("abcd" > "abc", "abc > abcd failed");
739ok("abce" > "abcd", "abce > abce failed");
740ok("x" > "", "\"x\" > \"\" failed");
741ok(!(0 > 0), "0 > 0");
742
743ok(3.4 >= 1, "3.4 >= 1 failed");
744ok(!(1 >= 3.4), "1 >= 3.4");
745ok("abcd" >= "abc", "abc >= abcd failed");
746ok("abce" >= "abcd", "abce >= abce failed");
747ok("x" >= "", "\"x\" >= \"\" failed");
748ok(0 >= 0, "0 >= 0");
749
750tmp = 1;
751ok(++tmp === 2, "++tmp (1) is not 2");
752ok(tmp === 2, "incremented tmp is not 2");
753ok(--tmp === 1, "--tmp (2) is not 1");
754ok(tmp === 1, "decremented tmp is not 1");
755ok(tmp++ === 1, "tmp++ (1) is not 1");
756ok(tmp === 2, "incremented tmp(1) is not 2");
757ok(tmp-- === 2, "tmp-- (2) is not 2");
758ok(tmp === 1, "decremented tmp is not 1");
759
760tmp = new Object();
761tmp.iii++;
762ok(isNaN(tmp.iii), "tmp.iii = " + tmp.iii);
763
764String.prototype.test = true;
765ok("".test === true, "\"\".test is not true");
766
767Boolean.prototype.test = true;
768ok(true.test === true, "true.test is not true");
769
770Number.prototype.test = true;
771ok((0).test === true, "(0).test is not true");
772ok((0.5).test === true, "(0.5).test is not true");
773
774var state = "";
775try {
776    ok(state === "", "try: state = " + state);
777    state = "try";
778}catch(ex) {
779    ok(false, "unexpected catch");
780}
781ok(state === "try", "state = " + state + " expected try");
782
783state = "";
784try {
785    ok(state === "", "try: state = " + state);
786    state = "try";
787}finally {
788    ok(state === "try", "finally: state = " + state);
789    state = "finally";
790}
791ok(state === "finally", "state = " + state + " expected finally");
792
793state = "";
794try {
795    try {
796        throw 0;
797    }finally {
798        state = "finally";
799    }
800}catch(e) {
801    ok(state === "finally", "state = " + state + " expected finally");
802    state = "catch";
803}
804ok(state === "catch", "state = " + state + " expected catch");
805
806try {
807    try {
808        throw 0;
809    }finally {
810        throw 1;
811    }
812}catch(e) {
813    ok(e === 1, "e = " + e);
814}
815
816state = "";
817try {
818    ok(state === "", "try: state = " + state);
819    state = "try";
820}catch(ex) {
821    ok(false, "unexpected catch");
822}finally {
823    ok(state === "try", "finally: state = " + state);
824    state = "finally";
825}
826ok(state === "finally", "state = " + state + " expected finally");
827
828var state = "";
829try {
830    ok(state === "", "try: state = " + state);
831    state = "try";
832    throw "except";
833}catch(ex) {
834    ok(state === "try", "catch: state = " + state);
835    ok(ex === "except", "ex is not \"except\"");
836    state = "catch";
837}
838ok(state === "catch", "state = " + state + " expected catch");
839
840var state = "";
841try {
842    ok(state === "", "try: state = " + state);
843    state = "try";
844    throw true;
845}catch(ex) {
846    ok(state === "try", "catch: state = " + state);
847    ok(ex === true, "ex is not true");
848    state = "catch";
849}finally {
850    ok(state === "catch", "finally: state = " + state);
851    state = "finally";
852}
853ok(state === "finally", "state = " + state + " expected finally");
854
855var state = "";
856try {
857    ok(state === "", "try: state = " + state);
858    state = "try";
859    try { throw true; } finally {}
860}catch(ex) {
861    ok(state === "try", "catch: state = " + state);
862    ok(ex === true, "ex is not true");
863    state = "catch";
864}finally {
865    ok(state === "catch", "finally: state = " + state);
866    state = "finally";
867}
868ok(state === "finally", "state = " + state + " expected finally");
869
870var state = "";
871try {
872    ok(state === "", "try: state = " + state);
873    state = "try";
874    try { throw "except"; } catch(ex) { throw true; }
875}catch(ex) {
876    ok(state === "try", "catch: state = " + state);
877    ok(ex === true, "ex is not true");
878    state = "catch";
879}finally {
880    ok(state === "catch", "finally: state = " + state);
881    state = "finally";
882}
883ok(state === "finally", "state = " + state + " expected finally");
884
885function throwFunc(x) {
886    throw x;
887}
888
889var state = "";
890try {
891    ok(state === "", "try: state = " + state);
892    state = "try";
893    throwFunc(true);
894}catch(ex) {
895    ok(state === "try", "catch: state = " + state);
896    ok(ex === true, "ex is not true");
897    state = "catch";
898}finally {
899    ok(state === "catch", "finally: state = " + state);
900    state = "finally";
901}
902ok(state === "finally", "state = " + state + " expected finally");
903
904state = "";
905switch(1) {
906case "1":
907    ok(false, "unexpected case \"1\"");
908case 1:
909    ok(state === "", "case 1: state = " + state);
910    state = "1";
911default:
912    ok(state === "1", "default: state = " + state);
913    state = "default";
914case false:
915    ok(state === "default", "case false: state = " + state);
916    state = "false";
917}
918ok(state === "false", "state = " + state);
919
920state = "";
921switch("") {
922case "1":
923case 1:
924    ok(false, "unexpected case 1");
925default:
926    ok(state === "", "default: state = " + state);
927    state = "default";
928case false:
929    ok(state === "default", "case false: state = " + state);
930    state = "false";
931}
932ok(state === "false", "state = " + state);
933
934state = "";
935switch(1) {
936case "1":
937    ok(false, "unexpected case \"1\"");
938case 1:
939    ok(state === "", "case 1: state = " + state);
940    state = "1";
941default:
942    ok(state === "1", "default: state = " + state);
943    state = "default";
944    break;
945case false:
946    ok(false, "unexpected case false");
947}
948ok(state === "default", "state = " + state);
949
950switch(1) {
951case 2:
952    ok(false, "unexpected case 2");
953case 3:
954    ok(false, "unexpected case 3");
955}
956
957switch(1) {
958case 2:
959    ok(false, "unexpected case 2");
960    break;
961default:
962    /* empty default */
963}
964
965switch(2) {
966default:
967    ok(false, "unexpected default");
968    break;
969case 2:
970    /* empty case */
971};
972
973switch(2) {
974default:
975    ok(false, "unexpected default");
976    break;
977case 1:
978case 2:
979case 3:
980    /* empty case */
981};
982
983(function() {
984    var i=0;
985
986    switch(1) {
987    case 1:
988        i++;
989    }
990    return i;
991})();
992
993(function() {
994    var ret, x;
995
996    function unreachable() {
997        ok(false, "unreachable");
998    }
999
1000    function expect(value, expect_value) {
1001        ok(value === expect_value, "got " + value + " expected " + expect_value);
1002    }
1003
1004    ret = (function() {
1005        try {
1006            return "try";
1007            unreachable();
1008        }catch(e) {
1009            unreachable();
1010        }finally {
1011            return "finally";
1012            unreachable();
1013        }
1014        unreachable();
1015    })();
1016    expect(ret, "finally");
1017
1018    x = "";
1019    ret = (function() {
1020        try {
1021            x += "try,";
1022            return x;
1023            unreachable();
1024        }catch(e) {
1025            unreachable();
1026        }finally {
1027            x += "finally,";
1028        }
1029        unreachable();
1030    })();
1031    expect(ret, "try,");
1032    expect(x, "try,finally,");
1033
1034    x = "";
1035    ret = (function() {
1036        try {
1037            x += "try,"
1038            throw 1;
1039            unreachable();
1040        }catch(e) {
1041            x += "catch,";
1042            return "catch";
1043            unreachable();
1044        }finally {
1045            x += "finally,";
1046            return "finally";
1047            unreachable();
1048        }
1049        unreachable();
1050    })();
1051    expect(ret, "finally");
1052    expect(x, "try,catch,finally,");
1053
1054    x = "";
1055    ret = (function() {
1056        try {
1057            x += "try,"
1058            throw 1;
1059            unreachable();
1060        }catch(e) {
1061            x += "catch,";
1062            return "catch";
1063            unreachable();
1064        }finally {
1065            x += "finally,";
1066        }
1067        unreachable();
1068    })();
1069    expect(ret, "catch");
1070    expect(x, "try,catch,finally,");
1071
1072    x = "";
1073    ret = (function() {
1074        try {
1075            x += "try,"
1076            try {
1077                x += "try2,";
1078                return "try2";
1079            }catch(e) {
1080                unreachable();
1081            }finally {
1082                x += "finally2,";
1083            }
1084            unreachable();
1085        }catch(e) {
1086            unreachable();
1087        }finally {
1088            x += "finally,";
1089        }
1090        unreachable();
1091    })();
1092    expect(ret, "try2");
1093    expect(x, "try,try2,finally2,finally,");
1094
1095    x = "";
1096    ret = (function() {
1097        while(true) {
1098            try {
1099                x += "try,"
1100                try {
1101                    x += "try2,";
1102                    break;
1103                }catch(e) {
1104                    unreachable();
1105                }finally {
1106                    x += "finally2,";
1107                }
1108                unreachable();
1109            }catch(e) {
1110                unreachable();
1111            }finally {
1112                x += "finally,";
1113            }
1114            unreachable();
1115        }
1116        x += "ret";
1117        return "ret";
1118    })();
1119    expect(ret, "ret");
1120    expect(x, "try,try2,finally2,finally,ret");
1121
1122    x = "";
1123    ret = (function() {
1124        while(true) {
1125            try {
1126                x += "try,"
1127                try {
1128                    x += "try2,";
1129                    continue;
1130                }catch(e) {
1131                    unreachable();
1132                }finally {
1133                    x += "finally2,";
1134                }
1135                unreachable();
1136            }catch(e) {
1137                unreachable();
1138            }finally {
1139                x += "finally,";
1140                break;
1141            }
1142            unreachable();
1143        }
1144        x += "ret";
1145        return "ret";
1146    })();
1147    expect(ret, "ret");
1148    expect(x, "try,try2,finally2,finally,ret");
1149})();
1150
1151tmp = eval("1");
1152ok(tmp === 1, "eval(\"1\") !== 1");
1153eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
1154ok(tmp === 2, "tmp !== 2");
1155
1156ok(eval(false) === false, "eval(false) !== false");
1157ok(eval() === undefined, "eval() !== undefined");
1158
1159tmp = eval("1", "2");
1160ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
1161
1162var state = "";
1163try {
1164    ok(state === "", "try: state = " + state);
1165    state = "try";
1166    eval("throwFunc(true);");
1167}catch(ex) {
1168    ok(state === "try", "catch: state = " + state);
1169    ok(ex === true, "ex is not true");
1170    state = "catch";
1171}finally {
1172    ok(state === "catch", "finally: state = " + state);
1173    state = "finally";
1174}
1175ok(state === "finally", "state = " + state + " expected finally");
1176
1177tmp = [,,1,2,,,true];
1178ok(tmp.length === 7, "tmp.length !== 7");
1179ok(tmp["0"] === undefined, "tmp[0] is not undefined");
1180ok(tmp["3"] === 2, "tmp[3] !== 2");
1181ok(tmp["6"] === true, "tmp[6] !== true");
1182ok(tmp[2] === 1, "tmp[2] !== 1");
1183ok(!("0" in tmp), "0 found in array");
1184ok(!("1" in tmp), "1 found in array");
1185ok("2" in tmp, "2 not found in array");
1186ok(!("2" in [1,,,,]), "2 found in [1,,,,]");
1187
1188ok([1,].length === 2, "[1,].length !== 2");
1189ok([,,].length === 3, "[,,].length !== 3");
1190ok([,].length === 2, "[].length != 2");
1191ok([].length === 0, "[].length != 0");
1192
1193tmp = 0;
1194while(tmp < 4) {
1195    ok(tmp < 4, "tmp >= 4");
1196    tmp++;
1197}
1198ok(tmp === 4, "tmp !== 4");
1199
1200tmp = 0;
1201while(true) {
1202    ok(tmp < 4, "tmp >= 4");
1203    tmp++;
1204    if(tmp === 4) {
1205        break;
1206        ok(false, "break did not break");
1207    }
1208}
1209ok(tmp === 4, "tmp !== 4");
1210
1211tmp = 0;
1212do {
1213    ok(tmp < 4, "tmp >= 4");
1214    tmp++;
1215} while(tmp < 4);
1216ok(tmp === 4, "tmp !== 4");
1217
1218tmp = 0;
1219do {
1220    ok(tmp === 0, "tmp !=== 0");
1221    tmp++;
1222} while(false);
1223ok(tmp === 1, "tmp !== 1");
1224
1225tmp = 0;
1226do {
1227    ok(tmp < 4, "tmp >= 4");
1228    tmp++;
1229} while(tmp < 4)
1230ok(tmp === 4, "tmp !== 4")
1231
1232tmp = 0;
1233while(tmp < 4) {
1234    tmp++;
1235    if(tmp === 2) {
1236        continue;
1237        ok(false, "break did not break");
1238    }
1239    ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
1240}
1241ok(tmp === 4, "tmp !== 4");
1242
1243for(tmp=0; tmp < 4; tmp++)
1244    ok(tmp < 4, "tmp = " + tmp);
1245ok(tmp === 4, "tmp !== 4");
1246
1247for(tmp=0; tmp < 4; tmp++) {
1248    if(tmp === 2)
1249        break;
1250    ok(tmp < 2, "tmp = " + tmp);
1251}
1252ok(tmp === 2, "tmp !== 2");
1253
1254for(tmp=0; tmp < 4; tmp++) {
1255    if(tmp === 2)
1256        continue;
1257    ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
1258}
1259ok(tmp === 4, "tmp !== 4");
1260
1261for(var fi=0; fi < 4; fi++)
1262    ok(fi < 4, "fi = " + fi);
1263ok(fi === 4, "fi !== 4");
1264
1265tmp = true;
1266obj1 = new Object();
1267for(obj1.nonexistent; tmp; tmp = false)
1268    ok(!("nonexistent" in obj1), "nonexistent added to obj1");
1269
1270obj1 = new Object();
1271for(tmp in obj1.nonexistent)
1272    ok(false, "for(tmp in obj1.nonexistent) called with tmp = " + tmp);
1273ok(!("nonexistent" in obj1), "nonexistent added to obj1 by for..in loop");
1274
1275
1276var i, j;
1277
1278/* Previous versions have broken finally block implementation */
1279if(ScriptEngineMinorVersion() >= 8) {
1280    tmp = "";
1281    i = 0;
1282    while(true) {
1283        tmp += "1";
1284        for(i = 1; i < 3; i++) {
1285            switch(i) {
1286            case 1:
1287                tmp += "2";
1288                continue;
1289            case 2:
1290                tmp += "3";
1291                try {
1292                    throw null;
1293                }finally {
1294                    tmp += "4";
1295                    break;
1296                }
1297            default:
1298                ok(false, "unexpected state");
1299            }
1300            tmp += "5";
1301        }
1302        with({prop: "6"}) {
1303            tmp += prop;
1304            break;
1305        }
1306    }
1307    ok(tmp === "123456", "tmp = " + tmp);
1308}
1309
1310tmp = "";
1311i = 0;
1312for(j in [1,2,3]) {
1313    tmp += "1";
1314    for(;;) {
1315        with({prop: "2"}) {
1316            tmp += prop;
1317            try {
1318                throw "3";
1319            }catch(e) {
1320                tmp += e;
1321                with([0])
1322                    break;
1323            }
1324        }
1325        ok(false, "unexpected state");
1326    }
1327    while(true) {
1328        tmp += "4";
1329        break;
1330    }
1331    break;
1332}
1333ok(tmp === "1234", "tmp = " + tmp);
1334
1335tmp = 0;
1336for(var iter in [1,2,3]) {
1337    tmp += +iter;
1338    continue;
1339}
1340ok(tmp === 3, "tmp = " + tmp);
1341
1342tmp = false;
1343for(var iter in [1,2,3]) {
1344    switch(+iter) {
1345    case 1:
1346        tmp = true;
1347        try {
1348            continue;
1349        }finally {}
1350    default:
1351        continue;
1352    }
1353}
1354ok(tmp, "tmp = " + tmp);
1355
1356loop_label:
1357while(true) {
1358    while(true)
1359        break loop_label;
1360}
1361
1362loop_label: {
1363    tmp = 0;
1364    while(true) {
1365        while(true)
1366            break loop_label;
1367    }
1368    ok(false, "unexpected evaluation 1");
1369}
1370
1371while(true) {
1372    some_label: break;
1373    ok(false, "unexpected evaluation 2");
1374}
1375
1376just_label: tmp = 1;
1377ok(tmp === 1, "tmp != 1");
1378
1379some_label: break some_label;
1380
1381other_label: {
1382    break other_label;
1383    ok(false, "unexpected evaluation 3");
1384}
1385
1386loop_label:
1387do {
1388    while(true)
1389        continue loop_label;
1390}while(false);
1391
1392loop_label:
1393for(i = 0; i < 3; i++) {
1394    while(true)
1395        continue loop_label;
1396}
1397
1398loop_label:
1399other_label:
1400for(i = 0; i < 3; i++) {
1401    while(true)
1402        continue loop_label;
1403}
1404
1405loop_label:
1406for(tmp in {prop: false}) {
1407    while(true)
1408        continue loop_label;
1409}
1410
1411ok((void 1) === undefined, "(void 1) !== undefined");
1412
1413var inobj = new Object();
1414
1415for(var iter in inobj)
1416    ok(false, "unexpected iter = " + iter);
1417
1418inobj.test = true;
1419tmp = 0;
1420for(iter in inobj) {
1421    ok(iter == "test", "unexpected iter = " + iter);
1422    tmp++;
1423}
1424ok(tmp === 1, "for..in tmp = " + tmp);
1425
1426function forinTestObj() {}
1427
1428forinTestObj.prototype.test3 = true;
1429
1430var arr = new Array();
1431inobj = new forinTestObj();
1432inobj.test1 = true;
1433inobj.test2 = true;
1434
1435tmp = 0;
1436for(iter in inobj) {
1437    arr[iter] = true;
1438    tmp++;
1439}
1440
1441ok(tmp === 3, "for..in tmp = " + tmp);
1442ok(arr["test1"] === true, "arr[test1] !== true");
1443ok(arr["test2"] === true, "arr[test2] !== true");
1444ok(arr["test3"] === true, "arr[test3] !== true");
1445
1446tmp = new Object();
1447tmp.test = false;
1448ok((delete tmp.test) === true, "delete returned false");
1449ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1450ok(!("test" in tmp), "test is still in tmp after delete?");
1451for(iter in tmp)
1452    ok(false, "tmp has prop " + iter);
1453ok((delete tmp.test) === true, "deleting test didn't return true");
1454ok((delete tmp.nonexistent) === true, "deleting nonexistent didn't return true");
1455ok((delete nonexistent) === true, "deleting nonexistent didn't return true");
1456
1457tmp = new Object();
1458tmp.test = false;
1459ok((delete tmp["test"]) === true, "delete returned false");
1460ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1461ok(!("test" in tmp), "test is still in tmp after delete?");
1462
1463tmp.testWith = true;
1464with(tmp)
1465    ok(testWith === true, "testWith !== true");
1466
1467if(false) {
1468    var varTest1 = true;
1469}
1470
1471ok(varTest1 === undefined, "varTest1 = " + varTest1);
1472ok(varTest2 === undefined, "varTest2 = " + varTest1);
1473
1474var varTest2;
1475
1476function varTestFunc(varTest3) {
1477    var varTest3;
1478
1479    ok(varTest3 === 3, "varTest3 = " + varTest3);
1480    ok(varTest4 === undefined, "varTest4 = " + varTest4);
1481
1482    var varTest4;
1483}
1484
1485varTestFunc(3);
1486
1487deleteTest = 1;
1488delete deleteTest;
1489try {
1490    tmp = deleteTest;
1491    ok(false, "deleteTest not throwed exception?");
1492}catch(ex) {}
1493
1494(function() {
1495    var to_delete = 2;
1496    var r = delete to_delete;
1497    ok(r === false, "delete 1 returned " + r);
1498    if(r)
1499        return;
1500    ok(to_delete === 2, "to_delete = " + to_delete);
1501
1502    to_delete = new Object();
1503    r = delete to_delete;
1504    ok(r === false, "delete 2 returned " + r);
1505    ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
1506})();
1507
1508(function(to_delete) {
1509    var r = delete to_delete;
1510    ok(r === false, "delete 3 returned " + r);
1511    ok(to_delete === 2, "to_delete = " + to_delete);
1512
1513    to_delete = new Object();
1514    r = delete to_delete;
1515    ok(r === false, "delete 4 returned " + r);
1516    ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
1517})(2);
1518
1519(function() {
1520    with({to_delete: new Object()}) {
1521        var r = delete to_delete;
1522        ok(r === true, "delete returned " + r);
1523    }
1524})();
1525
1526if (false)
1527    if (true)
1528        ok(false, "if evaluated");
1529    else
1530        ok(false, "else should be associated with nearest if statement");
1531
1532if (true)
1533    if (false)
1534        ok(false, "if evaluated");
1535    else
1536        ok(true, "else should be associated with nearest if statement");
1537
1538function instanceOfTest() {}
1539tmp = new instanceOfTest();
1540
1541ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
1542ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1543ok((tmp instanceof String) === false, "tmp is instance of String");
1544
1545instanceOfTest.prototype = new Object();
1546ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
1547ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1548
1549ok((1 instanceof Object) === false, "1 is instance of Object");
1550ok((false instanceof Boolean) === false, "false is instance of Boolean");
1551ok(("" instanceof Object) === false, "'' is instance of Object");
1552
1553(function () {
1554    ok((arguments instanceof Object) === true, "argument is not instance of Object");
1555    ok((arguments instanceof Array) === false, "argument is not instance of Array");
1556    ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
1557})(1,2);
1558
1559obj = new String();
1560ok(("length" in obj) === true, "length is not in obj");
1561ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
1562ok(("abc" in obj) === false, "test is in obj");
1563obj.abc = 1;
1564ok(("abc" in obj) === true, "test is not in obj");
1565ok(("1" in obj) === false, "1 is in obj");
1566
1567obj = [1,2,3];
1568ok((1 in obj) === true, "1 is not in obj");
1569
1570obj = new Object();
1571try {
1572    obj.prop["test"];
1573    ok(false, "expected exception");
1574}catch(e) {}
1575ok(!("prop" in obj), "prop in obj");
1576
1577if(invokeVersion >= 2) {
1578    ok("test"[0] === "t", '"test"[0] = ' + test[0]);
1579    ok("test"[5] === undefined, '"test"[0] = ' + test[0]);
1580
1581    tmp = "test";
1582    ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1583    tmp[1] = "x";
1584    ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1585    ok(tmp["1"] === "e", "tmp['1'] = " + tmp["1"]);
1586    ok(tmp["0x1"] === undefined, "tmp['0x1'] = " + tmp["0x1"]);
1587}else {
1588    ok("test"[0] === undefined, '"test"[0] = ' + test[0]);
1589}
1590
1591ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
1592ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
1593ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
1594ok(isNaN() === true, "isNaN() !== true");
1595ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
1596ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
1597ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
1598
1599ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
1600ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
1601ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
1602ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
1603ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
1604ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
1605ok(isFinite() === false, "isFinite() !== false");
1606
1607ok((1 < NaN) === false, "(1 < NaN) !== false");
1608ok((1 > NaN) === false, "(1 > NaN) !== false");
1609ok((1 <= NaN) === false, "(1 <= NaN) !== false");
1610ok((1 >= NaN) === false, "(1 >= NaN) !== false");
1611ok((NaN < 1) === false, "(NaN < 1) !== false");
1612ok((NaN > 1) === false, "(NaN > 1) !== false");
1613ok((NaN <= 1) === false, "(NaN <= 1) !== false");
1614ok((NaN >= 1) === false, "(NaN >= 1) !== false");
1615ok((Infinity < 2) === false, "(Infinity < 2) !== false");
1616ok((Infinity > 2) === true, "(Infinity > 2) !== true");
1617ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
1618
1619ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
1620ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
1621ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
1622ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
1623ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
1624ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
1625
1626ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
1627ok((NaN === NaN) === false, "(NaN === NaN) !== false");
1628ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1629ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1630ok((0 === NaN) === false, "(0 === NaN) !== false");
1631
1632ok((NaN != NaN) === true, "(NaN !== NaN) != true");
1633ok((NaN == NaN) === false, "(NaN === NaN) != false");
1634ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1635ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1636ok((0 == NaN) === false, "(0 === NaN) != false");
1637
1638// escape tests
1639var escapeTests = [
1640    ["\'", "\\'", 39],
1641    ["\"", "\\\"", 34],
1642    ["\\", "\\\\", 92],
1643    ["\b", "\\b", 8],
1644    ["\t", "\\t", 9],
1645    ["\n", "\\n", 10],
1646    ["\v", "\\v", 118],
1647    ["\f", "\\f", 12],
1648    ["\r", "\\r", 13],
1649    ["\xf3", "\\xf3", 0xf3],
1650    ["\u1234", "\\u1234", 0x1234],
1651    ["\a", "\\a", 97],
1652    ["\?", "\\?", 63]
1653];
1654
1655for(i=0; i<escapeTests.length; i++) {
1656    tmp = escapeTests[i][0].charCodeAt(0);
1657    ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]);
1658}
1659
1660tmp = !+"\v1";
1661ok(tmp === true, '!+"\v1" = ' + tmp);
1662
1663ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
1664tmp = testFunc2(1);
1665ok(tmp === 2, "testFunc2(1) = " + tmp);
1666function testFunc2(x) { return x+1; }
1667
1668ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
1669tmp = testFunc3(1);
1670ok(tmp === 3, "testFunc3(1) = " + tmp);
1671tmp = function testFunc3(x) { return x+2; };
1672
1673tmp = testFunc4(1);
1674ok(tmp === 5, "testFunc4(1) = " + tmp);
1675tmp = function testFunc4(x) { return x+3; };
1676tmp = testFunc4(1);
1677testFunc4 = 1;
1678ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1679ok(tmp === 5, "testFunc4(1) = " + tmp);
1680tmp = function testFunc4(x) { return x+4; };
1681ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1682
1683function testEmbeddedFunctions() {
1684    ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
1685    tmp = testFunc5(1);
1686    ok(tmp === 3, "testFunc5(1) = " + tmp);
1687    tmp = function testFunc5(x) { return x+2; };
1688
1689    tmp = testFunc6(1);
1690    ok(tmp === 5, "testFunc6(1) = " + tmp);
1691    tmp = function testFunc6(x) { return x+3; };
1692    tmp = testFunc6(1);
1693    ok(tmp === 5, "testFunc6(1) = " + tmp);
1694    tmp = function testFunc6(x) { return x+4; };
1695    testFunc6 = 1;
1696    ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
1697}
1698
1699testEmbeddedFunctions();
1700
1701date = new Date();
1702date.toString = function() { return "toString"; }
1703ok(""+date === "toString", "''+date = " + date);
1704date.toString = function() { return this; }
1705ok(""+date === ""+date.valueOf(), "''+date = " + date);
1706
1707str = new String("test");
1708str.valueOf = function() { return "valueOf"; }
1709ok(""+str === "valueOf", "''+str = " + str);
1710str.valueOf = function() { return new Date(); }
1711ok(""+str === "test", "''+str = " + str);
1712
1713ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
1714
1715var re = /=(\?|%3F)/g;
1716ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
1717
1718tmp = new Array();
1719for(var i=0; i<2; i++)
1720    tmp[i] = /b/;
1721ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
1722
1723ok(isNullBSTR(getNullBSTR()), "isNullBSTR(getNullBSTR()) failed\n");
1724ok(getNullBSTR() === '', "getNullBSTR() !== ''");
1725ok(+getNullBSTR() === 0 , "+getNullBTR() !=== 0");
1726
1727ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1728ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1729ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
1730ok(nullDisp !== re, "nullDisp === re");
1731ok(nullDisp === null, "nullDisp === null");
1732ok(nullDisp == null, "nullDisp == null");
1733ok(getVT(true && nullDisp) === "VT_DISPATCH",
1734   "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
1735ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1736ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1737ok(nullDisp != new Object(), "nullDisp == new Object()");
1738ok(new Object() != nullDisp, "new Object() == nullDisp");
1739ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1740tmp = getVT(Object(nullDisp));
1741ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1742tmp = Object(nullDisp).toString();
1743ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1744
1745function do_test() {}
1746function nosemicolon() {} nosemicolon();
1747function () {} nosemicolon();
1748
1749if(false) {
1750    function in_if_false() { return true; } ok(false, "!?");
1751}
1752
1753ok(in_if_false(), "in_if_false failed");
1754
1755(function() { newValue = 1; })();
1756ok(newValue === 1, "newValue = " + newValue);
1757
1758obj = {undefined: 3};
1759
1760ok(typeof(name_override_func) === "function", "typeof(name_override_func) = " + typeof(name_override_func));
1761name_override_func = 3;
1762ok(name_override_func === 3, "name_override_func = " + name_override_func);
1763function name_override_func() {};
1764ok(name_override_func === 3, "name_override_func = " + name_override_func);
1765
1766tmp = (function() {
1767    var ret = false;
1768    with({ret: true})
1769        return ret;
1770})();
1771ok(tmp, "tmp = " + tmp);
1772
1773tmp = (function() {
1774    for(var iter in [1,2,3,4]) {
1775        var ret = false;
1776        with({ret: true})
1777            return ret;
1778    }
1779})();
1780ok(tmp, "tmp = " + tmp);
1781
1782(function() {
1783    ok(typeof(func) === "function", "typeof(func)  = " + typeof(func));
1784    with(new Object()) {
1785        var x = false && function func() {};
1786    }
1787    ok(typeof(func) === "function", "typeof(func)  = " + typeof(func));
1788})();
1789
1790(function() {
1791    ok(x === undefined, "x = " + x); // x is declared, but never initialized
1792    with({x: 1}) {
1793        ok(x === 1, "x = " + x);
1794        var x = 2;
1795        ok(x === 2, "x = " + x);
1796    }
1797    ok(x === undefined, "x = " + x);
1798})();
1799
1800/* NoNewline rule parser tests */
1801while(true) {
1802    if(true) break
1803    tmp = false
1804}
1805
1806while(true) {
1807    if(true) break /*
1808                    * no semicolon, but comment present */
1809    tmp = false
1810}
1811
1812while(true) {
1813    if(true) break // no semicolon, but comment present
1814    tmp = false
1815}
1816
1817while(true) {
1818    break
1819    continue
1820    tmp = false
1821}
1822
1823function returnTest() {
1824    return
1825    true;
1826}
1827
1828ok(returnTest() === undefined, "returnTest = " + returnTest());
1829
1830ActiveXObject = 1;
1831ok(ActiveXObject === 1, "ActiveXObject = " + ActiveXObject);
1832
1833Boolean = 1;
1834ok(Boolean === 1, "Boolean = " + Boolean);
1835
1836Object = 1;
1837ok(Object === 1, "Object = " + Object);
1838
1839Array = 1;
1840ok(Array === 1, "Array = " + Array);
1841
1842Date = 1;
1843ok(Date === 1, "Date = " + Date);
1844
1845Error = 1;
1846ok(Error === 1, "Error = " + Error);
1847
1848/* Keep this test in the end of file */
1849undefined = 6;
1850ok(undefined === 6, "undefined = " + undefined);
1851
1852NaN = 6;
1853ok(NaN === 6, "NaN !== 6");
1854
1855Infinity = 6;
1856ok(Infinity === 6, "Infinity !== 6");
1857
1858Math = 6;
1859ok(Math === 6, "NaN !== 6");
1860
1861reportSuccess();
1862