lang.js 50.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright 2008 Jacek Caban for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

19 20
var tmp;

21
ok(true, "true is not true?");
22 23 24 25 26
ok(!false, "!false is not true");
ok(!undefined, "!undefined is not true");
ok(!null, "!null is not true");
ok(!0, "!0 is not true");
ok(!0.0, "!0.0 is not true");
27

28 29 30 31 32 33 34 35
ok(1 === 1, "1 === 1 is false");
ok(!(1 === 2), "!(1 === 2) is false");
ok(1.0 === 1, "1.0 === 1 is false");
ok("abc" === "abc", "\"abc\" === \"abc\" is false");
ok(true === true, "true === true is false");
ok(null === null, "null === null is false");
ok(undefined === undefined, "undefined === undefined is false");
ok(!(undefined === null), "!(undefined === null) is false");
36 37
ok(1E0 === 1, "1E0 === 1 is false");
ok(1000000*1000000 === 1000000000000, "1000000*1000000 === 1000000000000 is false");
38
ok(8.64e15 === 8640000000000000, "8.64e15 !== 8640000000000000");
39
ok(1e2147483648 === Infinity, "1e2147483648 !== Infinity");
40

41 42 43 44 45 46 47 48 49 50
ok(00 === 0, "00 != 0");
ok(010 === 8, "010 != 8");
ok(077 === 63, "077 != 63");
ok(080 === 80, "080 != 80");
ok(090 === 90, "090 != 90");
ok(018 === 18, "018 != 18");
tmp = 07777777777777777777777;
ok(typeof(tmp) === "number" && tmp > 0xffffffff, "tmp = " + tmp);
tmp = 07777777779777777777777;
ok(typeof(tmp) === "number" && tmp > 0xffffffff, "tmp = " + tmp);
51 52 53
ok(0xffffffff === 4294967295, "0xffffffff = " + 0xffffffff);
tmp = 0x10000000000000000000000000000000000000000000000000000000000000000;
ok(tmp === Math.pow(2, 256), "0x1000...00 != 2^256");
54

55 56 57
ok(1 !== 2, "1 !== 2 is false");
ok(null !== undefined, "null !== undefined is false");

58 59 60 61 62 63 64 65 66 67 68 69
ok(1 == 1, "1 == 1 is false");
ok(!(1 == 2), "!(1 == 2) is false");
ok(1.0 == 1, "1.0 == 1 is false");
ok("abc" == "abc", "\"abc\" == \"abc\" is false");
ok(true == true, "true == true is false");
ok(null == null, "null == null is false");
ok(undefined == undefined, "undefined == undefined is false");
ok(undefined == null, "undefined == null is false");
ok(true == 1, "true == 1 is false");
ok(!(true == 2), "true == 2");
ok(0 == false, "0 == false is false");

70 71 72
ok(1 != 2, "1 != 2 is false");
ok(false != 1, "false != 1 is false");

73 74 75
ok(this === test, "this !== test");
eval('ok(this === test, "this !== test");');

76 77 78
var trueVar = true;
ok(trueVar, "trueVar is not true");

79 80
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 87
    ok(arguments["0"] === true, "arguments[0] is not true");
    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 92 93 94 95 96 97 98 99
    x = false;
    ok(arguments[0] === false, "arguments[0] is not false");
    arguments[1] = "x";
    ok(y === "x", "y = " + y);
    ok(arguments[1] === "x", "arguments[1] = " + arguments[1]);

    ok(arguments["0x0"] === undefined, "arguments['0x0'] = " + arguments["0x0"]);
    ok(arguments["x"] === undefined, "arguments['x'] = " + arguments["x"]);

100 101 102
    ok(this === test, "this !== test");
    eval('ok(this === test, "this !== test");');

103 104 105 106
    tmp = delete arguments;
    ok(tmp === false, "arguments deleted");
    ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments));

107 108 109 110
    x = 2;
    ok(x === 2, "x = " + x);
    ok(arguments[0] === 2, "arguments[0] = " + arguments[0]);

111 112 113 114
    return true;
}

ok(testFunc1.length === 2, "testFunc1.length is not 2");
115
ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
116

117 118
ok(Object.prototype !== undefined, "Object.prototype is undefined");
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 125
ok(Math !== undefined, "Math is undefined");
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 129
ok(Date.prototype !== undefined, "Date.prototype is undefined");
ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
130

131
function testConstructor(constr, name, inst) {
132
    ok(constr.prototype.constructor === constr, name + ".prototype.constructor !== " + name);
133 134 135 136 137 138 139
    ok(constr.prototype.hasOwnProperty("constructor"), name + ".prototype.hasOwnProperty('constructor')");

    if(!inst)
        inst = new constr();

    ok(inst.constructor === constr, "(new " + name + "()).constructor !== " + name);
    ok(!inst.hasOwnProperty("constructor"), "(new " + name + "()).hasOwnProperty('constructor')");
140 141 142 143 144 145 146
}

testConstructor(Object, "Object");
testConstructor(String, "String");
testConstructor(Array, "Array");
testConstructor(Boolean, "Boolean");
testConstructor(Number, "Number");
147
testConstructor(RegExp, "RegExp", /x/);
148
testConstructor(Function, "Function");
149
testConstructor(Date, "Date");
150
testConstructor(VBArray, "VBArray", new VBArray(createArray()));
151 152 153 154
testConstructor(Error, "Error");
testConstructor(EvalError, "EvalError");
testConstructor(RangeError, "RangeError");
testConstructor(ReferenceError, "ReferenceError");
155
testConstructor(RegExpError, "RegExpError");
156 157 158
testConstructor(SyntaxError, "SyntaxError");
testConstructor(TypeError, "TypeError");
testConstructor(URIError, "URIError");
159

160 161 162
Function.prototype.test = true;
ok(testFunc1.test === true, "testFunc1.test !== true");
ok(Function.test === true, "Function.test !== true");
163

164 165 166 167 168 169 170 171 172 173 174 175
ok(typeof(0) === "number", "typeof(0) is not number");
ok(typeof(1.5) === "number", "typeof(1.5) is not number");
ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
ok(typeof("") === "string", "typeof(\"\") is not string");
ok(typeof(true) === "boolean", "typeof(true) is not boolean");
ok(typeof(null) === "object", "typeof(null) is not object");
ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
ok(typeof(Math) === "object", "typeof(Math) is not object");
ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
ok(typeof(String) === "function", "typeof(String) is not function");
ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
176
ok(typeof(this) === "object", "typeof(this) is not object");
177 178 179 180 181
ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
tmp = typeof((new Object()).doesnotexist);
ok(tmp === "undefined", "typeof((new Object).doesnotexist = " + tmp);
tmp = typeof(testObj.onlyDispID);
ok(tmp === "unknown", "typeof(testObj.onlyDispID) = " + tmp);
182

183 184
ok(testFunc1(true, "test") === true, "testFunc1 not returned true");

185 186
ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);

187 188 189
(tmp) = 3;
ok(tmp === 3, "tmp = " + tmp);

190 191 192 193 194 195 196 197 198 199 200 201 202 203
function testRecFunc(x) {
    ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
    if(x) {
        testRecFunc(false);
        ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
        ok(testRecFunc.arguments[0] === true, "testRecFunc.arguments.x = " + testRecFunc.arguments[0]);
    }
}

testRecFunc.arguments = 5;
ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
testRecFunc(true);
ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);

204 205 206 207 208 209 210 211 212 213 214
function argumentsTest() {
    var save = arguments;
    with({arguments: 1}) {
        ok(arguments === 1, "arguments = " + arguments);
        (function() {
            ok(argumentsTest.arguments === save, "unexpected argumentsTest.arguments");
        })();
    }
    eval('ok(arguments === save, "unexpected arguments");');
    [1,2].sort(function() {
        ok(argumentsTest.arguments === save, "unexpected argumentsTest.arguments");
215
        return 1;
216 217
    });
}
218

219
argumentsTest();
220

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
// arguments object detached from its execution context
(function() {
    var args, get_x, set_x;

    function test_args(detached) {
        ok(args[0] === 1, "args[0] = " + args[0]);
        set_x(2);
        ok(args[0] === (detached ? 1 : 2), "args[0] = " + args[0] + " expected " + (detached ? 1 : 2));
        args[0] = 3;
        ok(get_x() === (detached ? 2 : 3), "get_x() = " + get_x());
        ok(args[0] === 3, "args[0] = " + args[0]);
    }

    (function(x) {
        args = arguments;
        get_x = function() { return x; };
        set_x = function(v) { x = v; };

        test_args(false);
        x = 1;
    })(1);

    test_args(true);
})();

// arguments is a regular variable, it may be overwritten
(function() {
    ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments));
    arguments = 1;
    ok(arguments === 1, "arguments = " + arguments);
})();

253 254 255 256
(function callAsExprTest() {
    ok(callAsExprTest.arguments === null, "callAsExprTest.arguments = " + callAsExprTest.arguments);
})(1,2);

257 258 259 260
tmp = (function() {1;})();
ok(tmp === undefined, "tmp = " + tmp);
tmp = eval("1;");
ok(tmp === 1, "tmp = " + tmp);
261 262
tmp = eval("1,2;");
ok(tmp === 2, "tmp = " + tmp);
263 264
tmp = eval("testNoRes(),2;");
ok(tmp === 2, "tmp = " + tmp);
265 266
tmp = eval("if(true) {3}");
ok(tmp === 3, "tmp = " + tmp);
267 268 269
eval("testRes(); testRes()");
tmp = eval("3; if(false) {4;} else {};;;")
ok(tmp === 3, "tmp = " + tmp);
270 271
tmp = eval("try { 1; } finally { 2; }")
ok(tmp === 2, "tmp = " + tmp);
272

273 274 275 276
testNoRes();
testRes() && testRes();
testNoRes(), testNoRes();

277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
(function() {
    eval("var x=1;");
    ok(x === 1, "x = " + x);
})();

(function() {
    var e = eval;
    var r = e(1);
    ok(r === 1, "r = " + r);
    (function(x, a) { x(a); })(eval, "2");
})();

(function(r) {
    r = eval("1");
    ok(r === 1, "r = " + r);
    (function(x, a) { x(a); })(eval, "2");
})();

295
tmp = (function(){ return testNoRes(), testRes();})();
296

297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
var f1, f2;

ok(funcexpr() == 2, "funcexpr() = " + funcexpr());

f1 = function funcexpr() { return 1; }
ok(f1 != funcexpr, "f1 == funcexpr");
ok(f1() === 1, "f1() = " + f1());

f2 = function funcexpr() { return 2; }
ok(f2 != funcexpr, "f2 != funcexpr");
ok(f2() === 2, "f2() = " + f2());

f1 = null;
for(i = 0; i < 3; i++) {
    f2 = function funcexpr2() {};
    ok(f1 != f2, "f1 == f2");
    f1 = f2;
}

f1 = null;
for(i = 0; i < 3; i++) {
    f2 = function() {};
    ok(f1 != f2, "f1 == f2");
    f1 = f2;
}

(function() {
    ok(infuncexpr() == 2, "infuncexpr() = " + infuncexpr());

    f1 = function infuncexpr() { return 1; }
    ok(f1 != funcexpr, "f1 == funcexpr");
    ok(f1() === 1, "f1() = " + f1());

    f2 = function infuncexpr() { return 2; }
    ok(f2 != funcexpr, "f2 != funcexpr");
    ok(f2() === 2, "f2() = " + f2());

    f1 = null;
    for(i = 0; i < 3; i++) {
        f2 = function infuncexpr2() {};
        ok(f1 != f2, "f1 == f2");
        f1 = f2;
    }

    f1 = null;
    for(i = 0; i < 3; i++) {
        f2 = function() {};
        ok(f1 != f2, "f1 == f2");
        f1 = f2;
    }
})();

349 350
var obj1 = new Object();
ok(typeof(obj1) === "object", "typeof(obj1) is not object");
351
ok(obj1.constructor === Object, "unexpected obj1.constructor");
352 353 354 355 356 357
obj1.test = true;
obj1.func = function () {
    ok(this === obj1, "this is not obj1");
    ok(this.test === true, "this.test is not true");
    ok(arguments.length === 1, "arguments.length is not 1");
    ok(arguments["0"] === true, "arguments[0] is not true");
358
    ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
359 360 361 362 363

    return "test";
};

ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
364

365 366 367 368 369 370
function testConstr1() {
    this.var1 = 1;

    ok(this !== undefined, "this is undefined");
    ok(arguments.length === 1, "arguments.length is not 1");
    ok(arguments["0"] === true, "arguments[0] is not 1");
371
    ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
372 373 374 375 376

    return false;
}

testConstr1.prototype.pvar = 1;
377
ok(testConstr1.prototype.constructor === testConstr1, "testConstr1.prototype.constructor !== testConstr1");
378 379 380

var obj2 = new testConstr1(true);
ok(typeof(obj2) === "object", "typeof(obj2) is not object");
381
ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
382
ok(obj2.pvar === 1, "obj2.pvar is not 1");
383
ok(!obj2.hasOwnProperty('constructor'), "obj2.hasOwnProperty('constructor')");
384 385 386 387 388 389 390 391

testConstr1.prototype.pvar = 2;
ok(obj2.pvar === 2, "obj2.pvar is not 2");

obj2.pvar = 3;
testConstr1.prototype.pvar = 1;
ok(obj2.pvar === 3, "obj2.pvar is not 3");

392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
obj1 = new Object();
function testConstr3() {
    return obj1;
}

obj2 = new testConstr3();
ok(obj1 === obj2, "obj1 != obj2");

function testConstr4() {
    return 2;
}

obj2 = new testConstr3();
ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));

407 408 409
var obj3 = new Object;
ok(typeof(obj3) === "object", "typeof(obj3) is not object");

410 411 412 413 414 415 416 417 418 419 420 421 422 423
(function() {
    ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
    function func() {}
    ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
    func = 0;
    ok(typeof(func) === "number", "typeof(func) = " + typeof(func));
})();

(function(f) {
    ok(typeof(f) === "function", "typeof(f) = " + typeof(f));
    function f() {};
    ok(typeof(f) === "function", "typeof(f) = " + typeof(f));
})(1);

424 425 426 427 428 429 430 431 432
for(var iter in "test")
    ok(false, "unexpected forin call, test = " + iter);

for(var iter in null)
    ok(false, "unexpected forin call, test = " + iter);

for(var iter in false)
    ok(false, "unexpected forin call, test = " + iter);

433 434 435
for(var iter in pureDisp)
    ok(false, "unexpected forin call in pureDisp object");

436 437
tmp = new Object();
ok(!tmp.nonexistent, "!tmp.nonexistent = " + !tmp.nonexistent);
438 439 440 441 442
ok(!("nonexistent" in tmp), "nonexistent is in tmp after '!' expression")

tmp = new Object();
ok((~tmp.nonexistent) === -1, "!tmp.nonexistent = " + ~tmp.nonexistent);
ok(!("nonexistent" in tmp), "nonexistent is in tmp after '~' expression")
443

444
tmp = new Object();
445
ok(isNaN(+tmp.nonexistent), "!tmp.nonexistent = " + (+tmp.nonexistent));
446 447
ok(!("nonexistent" in tmp), "nonexistent is in tmp after '+' expression")

448 449 450 451
tmp = new Object();
tmp[tmp.nonexistent];
ok(!("nonexistent" in tmp), "nonexistent is in tmp after array expression")

452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
tmp = 0;
if(true)
    tmp = 1;
else
    ok(false, "else evaluated");
ok(tmp === 1, "tmp !== 1, if not evaluated?");

tmp = 0;
if(1 === 0)
    ok(false, "if evaluated");
else
    tmp = 1;
ok(tmp === 1, "tmp !== 1, if not evaluated?");

if(false)
    ok(false, "if(false) evaluated");

tmp = 0;
if(true)
    tmp = 1;
ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");

474 475 476 477
if(false) {
}else {
}

478 479 480
var obj3 = { prop1: 1,  prop2: typeof(false) };
ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
481
ok(obj3.constructor === Object, "unexpected obj3.constructor");
482

483 484 485 486 487 488 489 490 491 492 493 494 495 496
if(invokeVersion >= 2) {
    eval("tmp = {prop: 'value',}");
    ok(tmp.prop === "value", "tmp.prop = " + tmp.prop);
    eval("tmp = {prop: 'value',second:2,}");
    ok(tmp.prop === "value", "tmp.prop = " + tmp.prop);
}else {
    try {
        eval("tmp = {prop: 'value',}");
    }catch(e) {
        tmp = true;
    }
    ok(tmp === true, "exception not fired");
}

497 498 499 500 501 502
{
    var blockVar = 1;
    blockVar = 2;
}
ok(blockVar === 2, "blockVar !== 2");

503 504 505
ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");

506 507 508
ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
509
ok(getVT(0.5) === "VT_R8", "getVT(0.5) is not VT_R8");
510 511 512 513
ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");

514 515 516 517 518 519 520 521 522 523 524 525
tmp = 2+2;
ok(tmp === 4, "2+2 !== 4");
ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");

tmp = 2+2.5;
ok(tmp === 4.5, "2+2.5 !== 4.5");
ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");

tmp = 1.5+2.5;
ok(tmp === 4, "1.4+2.5 !== 4");
ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");

526 527 528 529 530 531
tmp = 4-2;
ok(tmp === 2, "4-2 !== 2");
ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");

tmp = 4.5-2;
ok(tmp === 2.5, "4.5-2 !== 2.5");
532
ok(getVT(tmp) === "VT_R8", "getVT(4.5-2) !== VT_R8");
533

534 535 536 537
tmp = -2;
ok(tmp === 0-2, "-2 !== 0-2");
ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");

538 539 540 541 542 543 544 545 546
tmp = 2*3;
ok(tmp === 6, "2*3 !== 6");
ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");

tmp = 2*3.5;
ok(tmp === 7, "2*3.5 !== 7");
ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");

tmp = 2.5*3.5;
547 548 549
/* FIXME: the parser loses precision */
/* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
550 551
ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");

552 553 554 555
tmp = 2*.5;
ok(tmp === 1, "2*.5 !== 1");
ok(getVT(tmp) == "VT_I4", "getVT(2*.5) !== VT_I4");

556 557 558 559 560 561 562 563 564 565 566 567
tmp = 4/2;
ok(tmp === 2, "4/2 !== 2");
ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");

tmp = 4.5/1.5;
ok(tmp === 3, "4.5/1.5 !== 3");
ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");

tmp = 3/2;
ok(tmp === 1.5, "3/2 !== 1.5");
ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");

568 569 570 571 572 573 574 575 576 577 578 579
tmp = 3%2;
ok(tmp === 1, "3%2 = " + tmp);

tmp = 4%2;
ok(tmp ===0, "4%2 = " + tmp);

tmp = 3.5%1.5;
ok(tmp === 0.5, "3.5%1.5 = " + tmp);

tmp = 3%true;
ok(tmp === 0, "3%true = " + tmp);

580 581 582
tmp = "ab" + "cd";
ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");

583 584 585 586
tmp = 1;
ok((tmp += 1) === 2, "tmp += 1 !== 2");
ok(tmp === 2, "tmp !== 2");

587 588 589 590
tmp = 2;
ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
ok(tmp === 1, "tmp !=== 1");

591 592 593 594
tmp = 2;
ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
ok(tmp === 3, "tmp !=== 3");

595 596 597 598
tmp = 5;
ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
ok(tmp === 2.5, "tmp !=== 2.5");

599 600 601 602
tmp = 3;
ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
ok(tmp === 1, "tmp !== 1");

603 604 605
tmp = 8;
ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");

606 607 608
tmp = 8;
ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");

609 610 611
tmp = 8;
ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");

612 613 614 615 616 617
tmp = 3 || ok(false, "second or expression called");
ok(tmp === 3, "3 || (...) is not 3");

tmp = false || 2;
ok(tmp === 2, "false || 2 is not 2");

618 619 620 621 622 623 624 625 626
tmp = 0 && ok(false, "second and expression called");
ok(tmp === 0, "0 && (...) is not 0");

tmp = true && "test";
ok(tmp === "test", "true && \"test\" is not \"test\"");

tmp = true && 0;
ok(tmp === 0, "true && 0 is not 0");

627 628 629 630 631 632 633 634 635 636 637 638
tmp = 3 | 4;
ok(tmp === 7, "3 | 4 !== 7");
ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));

tmp = 3.5 | 0;
ok(tmp === 3, "3.5 | 0 !== 3");
ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));

tmp = -3.5 | 0;
ok(tmp === -3, "-3.5 | 0 !== -3");
ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));

639 640 641 642 643 644 645 646 647
tmp = 0 | NaN;
ok(tmp === 0, "0 | NaN = " + tmp);

tmp = 0 | Infinity;
ok(tmp === 0, "0 | NaN = " + tmp);

tmp = 0 | (-Infinity);
ok(tmp === 0, "0 | NaN = " + tmp);

648 649 650 651
tmp = 10;
ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));

652 653 654 655 656 657
tmp = (123 * Math.pow(2,32) + 2) | 0;
ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);

tmp = (-123 * Math.pow(2,32) + 2) | 0;
ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);

658 659 660 661 662 663 664 665 666 667 668 669
tmp = 3 & 5;
ok(tmp === 1, "3 & 5 !== 1");
ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));

tmp = 3.5 & 0xffff;
ok(tmp === 3, "3.5 & 0xffff !== 3 ");
ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));

tmp = (-3.5) & 0xffffffff;
ok(tmp === -3, "-3.5 & 0xffff !== -3");
ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));

670 671 672 673 674 675
tmp = 2 << 3;
ok(tmp === 16, "2 << 3 = " + tmp);

tmp = 2 << 35;
ok(tmp === 16, "2 << 35 = " + tmp);

676 677 678 679 680 681
tmp = 8 >> 2;
ok(tmp === 2, "8 >> 2 = " + tmp);

tmp = -64 >> 4;
ok(tmp === -4, "-64 >> 4 = " + tmp);

682 683 684 685 686 687
tmp = 8 >>> 2;
ok(tmp === 2, "8 >> 2 = " + tmp);

tmp = -64 >>> 4;
ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);

688 689 690
tmp = 4 >>> NaN;
ok(tmp === 4, "4 >>> NaN = " + tmp);

691 692 693 694
tmp = 10;
ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));

695 696 697 698
tmp = 0xf0f0^0xff00;
ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));

699 700 701 702
tmp = 5;
ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));

703 704 705 706
tmp = ~1;
ok(tmp === -2, "~1 !== -2");
ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));

707 708
ok((3,4) === 4, "(3,4) !== 4");

709
ok(+3 === 3, "+3 !== 3");
710 711 712
ok(+true === 1, "+true !== 1");
ok(+false === 0, "+false !== 0");
ok(+null === 0, "+null !== 0");
713 714 715 716 717
ok(+"0" === 0, "+'0' !== 0");
ok(+"3" === 3, "+'3' !== 3");
ok(+"-3" === -3, "+'-3' !== -3");
ok(+"0xff" === 255, "+'0xff' !== 255");
ok(+"3e3" === 3000, "+'3e3' !== 3000");
718

719
tmp = new Number(1);
720
ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
721
ok(tmp.constructor === Number, "unexpected tmp.constructor");
722
tmp = new String("1");
723
ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
724
ok(tmp.constructor === String, "unexpected tmp.constructor");
725

726 727 728
ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
729 730 731 732
ok("" + null === "null", "\"\" + null !== \"null\"");
ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
ok("" + true === "true", "\"\" + true !== \"true\"");
ok("" + false === "false", "\"\" + false !== \"false\"");
733 734
ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
735

736 737 738 739 740 741 742
ok(1 < 3.4, "1 < 3.4 failed");
ok(!(3.4 < 1), "3.4 < 1");
ok("abc" < "abcd", "abc < abcd failed");
ok("abcd" < "abce", "abce < abce failed");
ok("" < "x", "\"\" < \"x\" failed");
ok(!(0 < 0), "0 < 0");

743 744 745 746 747 748 749
ok(1 <= 3.4, "1 <= 3.4 failed");
ok(!(3.4 <= 1), "3.4 <= 1");
ok("abc" <= "abcd", "abc <= abcd failed");
ok("abcd" <= "abce", "abce <= abce failed");
ok("" <= "x", "\"\" <= \"x\" failed");
ok(0 <= 0, "0 <= 0 failed");

750 751 752 753 754 755 756
ok(3.4 > 1, "3.4 > 1 failed");
ok(!(1 > 3.4), "1 > 3.4");
ok("abcd" > "abc", "abc > abcd failed");
ok("abce" > "abcd", "abce > abce failed");
ok("x" > "", "\"x\" > \"\" failed");
ok(!(0 > 0), "0 > 0");

757 758 759 760 761 762 763
ok(3.4 >= 1, "3.4 >= 1 failed");
ok(!(1 >= 3.4), "1 >= 3.4");
ok("abcd" >= "abc", "abc >= abcd failed");
ok("abce" >= "abcd", "abce >= abce failed");
ok("x" >= "", "\"x\" >= \"\" failed");
ok(0 >= 0, "0 >= 0");

764 765 766
tmp = 1;
ok(++tmp === 2, "++tmp (1) is not 2");
ok(tmp === 2, "incremented tmp is not 2");
767 768
ok(--tmp === 1, "--tmp (2) is not 1");
ok(tmp === 1, "decremented tmp is not 1");
769 770
ok(tmp++ === 1, "tmp++ (1) is not 1");
ok(tmp === 2, "incremented tmp(1) is not 2");
771 772
ok(tmp-- === 2, "tmp-- (2) is not 2");
ok(tmp === 1, "decremented tmp is not 1");
773

774 775 776 777
tmp = new Object();
tmp.iii++;
ok(isNaN(tmp.iii), "tmp.iii = " + tmp.iii);

778
String.prototype.test = true;
779 780 781 782
ok("".test === true, "\"\".test is not true");

Boolean.prototype.test = true;
ok(true.test === true, "true.test is not true");
783

784 785 786 787
Number.prototype.test = true;
ok((0).test === true, "(0).test is not true");
ok((0.5).test === true, "(0.5).test is not true");

788 789 790 791 792 793 794 795 796 797 798 799 800 801
var state = "";
try {
    ok(state === "", "try: state = " + state);
    state = "try";
}catch(ex) {
    ok(false, "unexpected catch");
}
ok(state === "try", "state = " + state + " expected try");

state = "";
try {
    ok(state === "", "try: state = " + state);
    state = "try";
}finally {
802
    ok(state === "try", "finally: state = " + state);
803 804 805 806
    state = "finally";
}
ok(state === "finally", "state = " + state + " expected finally");

807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
state = "";
try {
    try {
        throw 0;
    }finally {
        state = "finally";
    }
}catch(e) {
    ok(state === "finally", "state = " + state + " expected finally");
    state = "catch";
}
ok(state === "catch", "state = " + state + " expected catch");

try {
    try {
        throw 0;
    }finally {
        throw 1;
    }
}catch(e) {
    ok(e === 1, "e = " + e);
}

830 831 832 833 834 835 836
state = "";
try {
    ok(state === "", "try: state = " + state);
    state = "try";
}catch(ex) {
    ok(false, "unexpected catch");
}finally {
837
    ok(state === "try", "finally: state = " + state);
838 839 840 841
    state = "finally";
}
ok(state === "finally", "state = " + state + " expected finally");

842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863
var state = "";
try {
    ok(state === "", "try: state = " + state);
    state = "try";
    throw "except";
}catch(ex) {
    ok(state === "try", "catch: state = " + state);
    ok(ex === "except", "ex is not \"except\"");
    state = "catch";
}
ok(state === "catch", "state = " + state + " expected catch");

var state = "";
try {
    ok(state === "", "try: state = " + state);
    state = "try";
    throw true;
}catch(ex) {
    ok(state === "try", "catch: state = " + state);
    ok(ex === true, "ex is not true");
    state = "catch";
}finally {
864
    ok(state === "catch", "finally: state = " + state);
865 866 867 868 869 870 871 872 873 874 875 876 877 878
    state = "finally";
}
ok(state === "finally", "state = " + state + " expected finally");

var state = "";
try {
    ok(state === "", "try: state = " + state);
    state = "try";
    try { throw true; } finally {}
}catch(ex) {
    ok(state === "try", "catch: state = " + state);
    ok(ex === true, "ex is not true");
    state = "catch";
}finally {
879
    ok(state === "catch", "finally: state = " + state);
880 881 882 883 884 885 886 887 888 889 890 891 892 893
    state = "finally";
}
ok(state === "finally", "state = " + state + " expected finally");

var state = "";
try {
    ok(state === "", "try: state = " + state);
    state = "try";
    try { throw "except"; } catch(ex) { throw true; }
}catch(ex) {
    ok(state === "try", "catch: state = " + state);
    ok(ex === true, "ex is not true");
    state = "catch";
}finally {
894
    ok(state === "catch", "finally: state = " + state);
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
    state = "finally";
}
ok(state === "finally", "state = " + state + " expected finally");

function throwFunc(x) {
    throw x;
}

var state = "";
try {
    ok(state === "", "try: state = " + state);
    state = "try";
    throwFunc(true);
}catch(ex) {
    ok(state === "try", "catch: state = " + state);
    ok(ex === true, "ex is not true");
    state = "catch";
}finally {
913
    ok(state === "catch", "finally: state = " + state);
914 915 916 917
    state = "finally";
}
ok(state === "finally", "state = " + state + " expected finally");

918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947
state = "";
switch(1) {
case "1":
    ok(false, "unexpected case \"1\"");
case 1:
    ok(state === "", "case 1: state = " + state);
    state = "1";
default:
    ok(state === "1", "default: state = " + state);
    state = "default";
case false:
    ok(state === "default", "case false: state = " + state);
    state = "false";
}
ok(state === "false", "state = " + state);

state = "";
switch("") {
case "1":
case 1:
    ok(false, "unexpected case 1");
default:
    ok(state === "", "default: state = " + state);
    state = "default";
case false:
    ok(state === "default", "case false: state = " + state);
    state = "false";
}
ok(state === "false", "state = " + state);

948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
state = "";
switch(1) {
case "1":
    ok(false, "unexpected case \"1\"");
case 1:
    ok(state === "", "case 1: state = " + state);
    state = "1";
default:
    ok(state === "1", "default: state = " + state);
    state = "default";
    break;
case false:
    ok(false, "unexpected case false");
}
ok(state === "default", "state = " + state);

964 965 966 967 968 969 970
switch(1) {
case 2:
    ok(false, "unexpected case 2");
case 3:
    ok(false, "unexpected case 3");
}

971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996
switch(1) {
case 2:
    ok(false, "unexpected case 2");
    break;
default:
    /* empty default */
}

switch(2) {
default:
    ok(false, "unexpected default");
    break;
case 2:
    /* empty case */
};

switch(2) {
default:
    ok(false, "unexpected default");
    break;
case 1:
case 2:
case 3:
    /* empty case */
};

997 998 999 1000 1001 1002 1003 1004 1005 1006
(function() {
    var i=0;

    switch(1) {
    case 1:
        i++;
    }
    return i;
})();

1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
(function() {
    var ret, x;

    function unreachable() {
        ok(false, "unreachable");
    }

    function expect(value, expect_value) {
        ok(value === expect_value, "got " + value + " expected " + expect_value);
    }

    ret = (function() {
        try {
            return "try";
            unreachable();
        }catch(e) {
            unreachable();
        }finally {
            return "finally";
            unreachable();
        }
        unreachable();
    })();
    expect(ret, "finally");

    x = "";
    ret = (function() {
        try {
            x += "try,";
            return x;
            unreachable();
        }catch(e) {
            unreachable();
        }finally {
            x += "finally,";
        }
        unreachable();
    })();
    expect(ret, "try,");
    expect(x, "try,finally,");

    x = "";
    ret = (function() {
        try {
            x += "try,"
            throw 1;
            unreachable();
        }catch(e) {
            x += "catch,";
            return "catch";
            unreachable();
        }finally {
            x += "finally,";
            return "finally";
            unreachable();
        }
        unreachable();
    })();
    expect(ret, "finally");
    expect(x, "try,catch,finally,");

    x = "";
    ret = (function() {
        try {
            x += "try,"
            throw 1;
            unreachable();
        }catch(e) {
            x += "catch,";
            return "catch";
            unreachable();
        }finally {
            x += "finally,";
        }
        unreachable();
    })();
    expect(ret, "catch");
    expect(x, "try,catch,finally,");

    x = "";
    ret = (function() {
        try {
            x += "try,"
            try {
                x += "try2,";
                return "try2";
            }catch(e) {
                unreachable();
            }finally {
                x += "finally2,";
            }
            unreachable();
        }catch(e) {
            unreachable();
        }finally {
            x += "finally,";
        }
        unreachable();
    })();
    expect(ret, "try2");
    expect(x, "try,try2,finally2,finally,");

    x = "";
    ret = (function() {
        while(true) {
            try {
                x += "try,"
                try {
                    x += "try2,";
                    break;
                }catch(e) {
                    unreachable();
                }finally {
                    x += "finally2,";
                }
                unreachable();
            }catch(e) {
                unreachable();
            }finally {
                x += "finally,";
            }
            unreachable();
        }
        x += "ret";
        return "ret";
    })();
    expect(ret, "ret");
    expect(x, "try,try2,finally2,finally,ret");

    x = "";
    ret = (function() {
        while(true) {
            try {
                x += "try,"
                try {
                    x += "try2,";
                    continue;
                }catch(e) {
                    unreachable();
                }finally {
                    x += "finally2,";
                }
                unreachable();
            }catch(e) {
                unreachable();
            }finally {
                x += "finally,";
                break;
            }
            unreachable();
        }
        x += "ret";
        return "ret";
    })();
    expect(ret, "ret");
    expect(x, "try,try2,finally2,finally,ret");
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183

    ret = (function() {
        try {
            return "try";
            unreachable();
        }catch(e) {
            unreachable();
        }finally {
            new Object();
            var tmp = (function() {
                var s = new String();
                try {
                    s.length;
                }finally {
                    return 1;
                }
            })();
        }
        unreachable();
    })();
    expect(ret, "try");
1184 1185
})();

1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
tmp = eval("1");
ok(tmp === 1, "eval(\"1\") !== 1");
eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
ok(tmp === 2, "tmp !== 2");

ok(eval(false) === false, "eval(false) !== false");
ok(eval() === undefined, "eval() !== undefined");

tmp = eval("1", "2");
ok(tmp === 1, "eval(\"1\", \"2\") !== 1");

var state = "";
try {
    ok(state === "", "try: state = " + state);
    state = "try";
    eval("throwFunc(true);");
}catch(ex) {
    ok(state === "try", "catch: state = " + state);
    ok(ex === true, "ex is not true");
    state = "catch";
}finally {
1207
    ok(state === "catch", "finally: state = " + state);
1208 1209 1210 1211
    state = "finally";
}
ok(state === "finally", "state = " + state + " expected finally");

1212 1213 1214 1215 1216
tmp = [,,1,2,,,true];
ok(tmp.length === 7, "tmp.length !== 7");
ok(tmp["0"] === undefined, "tmp[0] is not undefined");
ok(tmp["3"] === 2, "tmp[3] !== 2");
ok(tmp["6"] === true, "tmp[6] !== true");
1217
ok(tmp[2] === 1, "tmp[2] !== 1");
1218 1219 1220 1221
ok(!("0" in tmp), "0 found in array");
ok(!("1" in tmp), "1 found in array");
ok("2" in tmp, "2 not found in array");
ok(!("2" in [1,,,,]), "2 found in [1,,,,]");
1222

1223
ok([1,].length === 2, "[1,].length !== 2");
1224 1225 1226
ok([,,].length === 3, "[,,].length !== 3");
ok([,].length === 2, "[].length != 2");
ok([].length === 0, "[].length != 0");
1227

1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257
tmp = 0;
while(tmp < 4) {
    ok(tmp < 4, "tmp >= 4");
    tmp++;
}
ok(tmp === 4, "tmp !== 4");

tmp = 0;
while(true) {
    ok(tmp < 4, "tmp >= 4");
    tmp++;
    if(tmp === 4) {
        break;
        ok(false, "break did not break");
    }
}
ok(tmp === 4, "tmp !== 4");

tmp = 0;
do {
    ok(tmp < 4, "tmp >= 4");
    tmp++;
} while(tmp < 4);
ok(tmp === 4, "tmp !== 4");

tmp = 0;
do {
    ok(tmp === 0, "tmp !=== 0");
    tmp++;
} while(false);
1258
ok(tmp === 1, "tmp !== 1");
1259

1260 1261 1262 1263 1264 1265 1266
tmp = 0;
do {
    ok(tmp < 4, "tmp >= 4");
    tmp++;
} while(tmp < 4)
ok(tmp === 4, "tmp !== 4")

1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
tmp = 0;
while(tmp < 4) {
    tmp++;
    if(tmp === 2) {
        continue;
        ok(false, "break did not break");
    }
    ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
}
ok(tmp === 4, "tmp !== 4");

1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
for(tmp=0; tmp < 4; tmp++)
    ok(tmp < 4, "tmp = " + tmp);
ok(tmp === 4, "tmp !== 4");

for(tmp=0; tmp < 4; tmp++) {
    if(tmp === 2)
        break;
    ok(tmp < 2, "tmp = " + tmp);
}
ok(tmp === 2, "tmp !== 2");

for(tmp=0; tmp < 4; tmp++) {
    if(tmp === 2)
        continue;
    ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
}
ok(tmp === 4, "tmp !== 4");

for(var fi=0; fi < 4; fi++)
    ok(fi < 4, "fi = " + fi);
ok(fi === 4, "fi !== 4");

1300 1301 1302 1303 1304
tmp = true;
obj1 = new Object();
for(obj1.nonexistent; tmp; tmp = false)
    ok(!("nonexistent" in obj1), "nonexistent added to obj1");

1305 1306 1307 1308 1309
obj1 = new Object();
for(tmp in obj1.nonexistent)
    ok(false, "for(tmp in obj1.nonexistent) called with tmp = " + tmp);
ok(!("nonexistent" in obj1), "nonexistent added to obj1 by for..in loop");

1310

1311
var i, j;
1312

1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
/* Previous versions have broken finally block implementation */
if(ScriptEngineMinorVersion() >= 8) {
    tmp = "";
    i = 0;
    while(true) {
        tmp += "1";
        for(i = 1; i < 3; i++) {
            switch(i) {
            case 1:
                tmp += "2";
                continue;
            case 2:
                tmp += "3";
                try {
                    throw null;
                }finally {
                    tmp += "4";
                    break;
                }
            default:
                ok(false, "unexpected state");
1334
            }
1335 1336 1337 1338 1339
            tmp += "5";
        }
        with({prop: "6"}) {
            tmp += prop;
            break;
1340 1341
        }
    }
1342
    ok(tmp === "123456", "tmp = " + tmp);
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
}

tmp = "";
i = 0;
for(j in [1,2,3]) {
    tmp += "1";
    for(;;) {
        with({prop: "2"}) {
            tmp += prop;
            try {
                throw "3";
            }catch(e) {
                tmp += e;
                with([0])
                    break;
            }
        }
        ok(false, "unexpected state");
    }
    while(true) {
        tmp += "4";
        break;
    }
    break;
}
ok(tmp === "1234", "tmp = " + tmp);

1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389
tmp = 0;
for(var iter in [1,2,3]) {
    tmp += +iter;
    continue;
}
ok(tmp === 3, "tmp = " + tmp);

tmp = false;
for(var iter in [1,2,3]) {
    switch(+iter) {
    case 1:
        tmp = true;
        try {
            continue;
        }finally {}
    default:
        continue;
    }
}
ok(tmp, "tmp = " + tmp);
1390

1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445
loop_label:
while(true) {
    while(true)
        break loop_label;
}

loop_label: {
    tmp = 0;
    while(true) {
        while(true)
            break loop_label;
    }
    ok(false, "unexpected evaluation 1");
}

while(true) {
    some_label: break;
    ok(false, "unexpected evaluation 2");
}

just_label: tmp = 1;
ok(tmp === 1, "tmp != 1");

some_label: break some_label;

other_label: {
    break other_label;
    ok(false, "unexpected evaluation 3");
}

loop_label:
do {
    while(true)
        continue loop_label;
}while(false);

loop_label:
for(i = 0; i < 3; i++) {
    while(true)
        continue loop_label;
}

loop_label:
other_label:
for(i = 0; i < 3; i++) {
    while(true)
        continue loop_label;
}

loop_label:
for(tmp in {prop: false}) {
    while(true)
        continue loop_label;
}

1446 1447
ok((void 1) === undefined, "(void 1) !== undefined");

1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480
var inobj = new Object();

for(var iter in inobj)
    ok(false, "unexpected iter = " + iter);

inobj.test = true;
tmp = 0;
for(iter in inobj) {
    ok(iter == "test", "unexpected iter = " + iter);
    tmp++;
}
ok(tmp === 1, "for..in tmp = " + tmp);

function forinTestObj() {}

forinTestObj.prototype.test3 = true;

var arr = new Array();
inobj = new forinTestObj();
inobj.test1 = true;
inobj.test2 = true;

tmp = 0;
for(iter in inobj) {
    arr[iter] = true;
    tmp++;
}

ok(tmp === 3, "for..in tmp = " + tmp);
ok(arr["test1"] === true, "arr[test1] !== true");
ok(arr["test2"] === true, "arr[test2] !== true");
ok(arr["test3"] === true, "arr[test3] !== true");

1481 1482 1483 1484
tmp = new Object();
tmp.test = false;
ok((delete tmp.test) === true, "delete returned false");
ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1485
ok(!("test" in tmp), "test is still in tmp after delete?");
1486 1487
for(iter in tmp)
    ok(false, "tmp has prop " + iter);
1488 1489
ok((delete tmp.test) === true, "deleting test didn't return true");
ok((delete tmp.nonexistent) === true, "deleting nonexistent didn't return true");
1490
ok((delete nonexistent) === true, "deleting nonexistent didn't return true");
1491

1492 1493 1494 1495 1496 1497
tmp = new Object();
tmp.test = false;
ok((delete tmp["test"]) === true, "delete returned false");
ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
ok(!("test" in tmp), "test is still in tmp after delete?");

1498 1499 1500 1501
tmp.testWith = true;
with(tmp)
    ok(testWith === true, "testWith !== true");

1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
if(false) {
    var varTest1 = true;
}

ok(varTest1 === undefined, "varTest1 = " + varTest1);
ok(varTest2 === undefined, "varTest2 = " + varTest1);

var varTest2;

function varTestFunc(varTest3) {
    var varTest3;

    ok(varTest3 === 3, "varTest3 = " + varTest3);
    ok(varTest4 === undefined, "varTest4 = " + varTest4);

    var varTest4;
}

1520 1521
varTestFunc(3);

1522 1523 1524 1525 1526 1527 1528
deleteTest = 1;
delete deleteTest;
try {
    tmp = deleteTest;
    ok(false, "deleteTest not throwed exception?");
}catch(ex) {}

1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
(function() {
    var to_delete = 2;
    var r = delete to_delete;
    ok(r === false, "delete 1 returned " + r);
    if(r)
        return;
    ok(to_delete === 2, "to_delete = " + to_delete);

    to_delete = new Object();
    r = delete to_delete;
    ok(r === false, "delete 2 returned " + r);
    ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
})();

(function(to_delete) {
    var r = delete to_delete;
    ok(r === false, "delete 3 returned " + r);
    ok(to_delete === 2, "to_delete = " + to_delete);

    to_delete = new Object();
    r = delete to_delete;
    ok(r === false, "delete 4 returned " + r);
    ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
})(2);

(function() {
    with({to_delete: new Object()}) {
        var r = delete to_delete;
        ok(r === true, "delete returned " + r);
    }
})();

1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572
if (false)
    if (true)
        ok(false, "if evaluated");
    else
        ok(false, "else should be associated with nearest if statement");

if (true)
    if (false)
        ok(false, "if evaluated");
    else
        ok(true, "else should be associated with nearest if statement");

1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
function instanceOfTest() {}
tmp = new instanceOfTest();

ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
ok((tmp instanceof Object) === true, "tmp is not instance of Object");
ok((tmp instanceof String) === false, "tmp is instance of String");

instanceOfTest.prototype = new Object();
ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
ok((tmp instanceof Object) === true, "tmp is not instance of Object");

ok((1 instanceof Object) === false, "1 is instance of Object");
ok((false instanceof Boolean) === false, "false is instance of Boolean");
ok(("" instanceof Object) === false, "'' is instance of Object");

1588 1589 1590 1591 1592 1593
(function () {
    ok((arguments instanceof Object) === true, "argument is not instance of Object");
    ok((arguments instanceof Array) === false, "argument is not instance of Array");
    ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
})(1,2);

1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604
obj = new String();
ok(("length" in obj) === true, "length is not in obj");
ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
ok(("abc" in obj) === false, "test is in obj");
obj.abc = 1;
ok(("abc" in obj) === true, "test is not in obj");
ok(("1" in obj) === false, "1 is in obj");

obj = [1,2,3];
ok((1 in obj) === true, "1 is not in obj");

1605 1606 1607 1608 1609 1610 1611
obj = new Object();
try {
    obj.prop["test"];
    ok(false, "expected exception");
}catch(e) {}
ok(!("prop" in obj), "prop in obj");

1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625
if(invokeVersion >= 2) {
    ok("test"[0] === "t", '"test"[0] = ' + test[0]);
    ok("test"[5] === undefined, '"test"[0] = ' + test[0]);

    tmp = "test";
    ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
    tmp[1] = "x";
    ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
    ok(tmp["1"] === "e", "tmp['1'] = " + tmp["1"]);
    ok(tmp["0x1"] === undefined, "tmp['0x1'] = " + tmp["0x1"]);
}else {
    ok("test"[0] === undefined, '"test"[0] = ' + test[0]);
}

1626
ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
1627
ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
1628
ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
1629
ok(isNaN() === true, "isNaN() !== true");
1630 1631
ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
1632
ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
1633

1634
ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
1635 1636
ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
1637 1638 1639 1640 1641
ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
ok(isFinite() === false, "isFinite() !== false");

1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653
ok((1 < NaN) === false, "(1 < NaN) !== false");
ok((1 > NaN) === false, "(1 > NaN) !== false");
ok((1 <= NaN) === false, "(1 <= NaN) !== false");
ok((1 >= NaN) === false, "(1 >= NaN) !== false");
ok((NaN < 1) === false, "(NaN < 1) !== false");
ok((NaN > 1) === false, "(NaN > 1) !== false");
ok((NaN <= 1) === false, "(NaN <= 1) !== false");
ok((NaN >= 1) === false, "(NaN >= 1) !== false");
ok((Infinity < 2) === false, "(Infinity < 2) !== false");
ok((Infinity > 2) === true, "(Infinity > 2) !== true");
ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");

1654 1655 1656 1657 1658 1659 1660
ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");

1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672
ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
ok((NaN === NaN) === false, "(NaN === NaN) !== false");
ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
ok((0 === NaN) === false, "(0 === NaN) !== false");

ok((NaN != NaN) === true, "(NaN !== NaN) != true");
ok((NaN == NaN) === false, "(NaN === NaN) != false");
ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
ok((0 == NaN) === false, "(0 === NaN) != false");

1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696
// escape tests
var escapeTests = [
    ["\'", "\\'", 39],
    ["\"", "\\\"", 34],
    ["\\", "\\\\", 92],
    ["\b", "\\b", 8],
    ["\t", "\\t", 9],
    ["\n", "\\n", 10],
    ["\v", "\\v", 118],
    ["\f", "\\f", 12],
    ["\r", "\\r", 13],
    ["\xf3", "\\xf3", 0xf3],
    ["\u1234", "\\u1234", 0x1234],
    ["\a", "\\a", 97],
    ["\?", "\\?", 63]
];

for(i=0; i<escapeTests.length; i++) {
    tmp = escapeTests[i][0].charCodeAt(0);
    ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]);
}

tmp = !+"\v1";
ok(tmp === true, '!+"\v1" = ' + tmp);
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717

ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
tmp = testFunc2(1);
ok(tmp === 2, "testFunc2(1) = " + tmp);
function testFunc2(x) { return x+1; }

ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
tmp = testFunc3(1);
ok(tmp === 3, "testFunc3(1) = " + tmp);
tmp = function testFunc3(x) { return x+2; };

tmp = testFunc4(1);
ok(tmp === 5, "testFunc4(1) = " + tmp);
tmp = function testFunc4(x) { return x+3; };
tmp = testFunc4(1);
testFunc4 = 1;
ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
ok(tmp === 5, "testFunc4(1) = " + tmp);
tmp = function testFunc4(x) { return x+4; };
ok(testFunc4 === 1, "testFunc4 = " + testFunc4);

1718
function testEmbeddedFunctions() {
1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733
    ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
    tmp = testFunc5(1);
    ok(tmp === 3, "testFunc5(1) = " + tmp);
    tmp = function testFunc5(x) { return x+2; };

    tmp = testFunc6(1);
    ok(tmp === 5, "testFunc6(1) = " + tmp);
    tmp = function testFunc6(x) { return x+3; };
    tmp = testFunc6(1);
    ok(tmp === 5, "testFunc6(1) = " + tmp);
    tmp = function testFunc6(x) { return x+4; };
    testFunc6 = 1;
    ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
}

1734
testEmbeddedFunctions();
1735

1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747
date = new Date();
date.toString = function() { return "toString"; }
ok(""+date === "toString", "''+date = " + date);
date.toString = function() { return this; }
ok(""+date === ""+date.valueOf(), "''+date = " + date);

str = new String("test");
str.valueOf = function() { return "valueOf"; }
ok(""+str === "valueOf", "''+str = " + str);
str.valueOf = function() { return new Date(); }
ok(""+str === "test", "''+str = " + str);

1748 1749
ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());

1750 1751 1752
var re = /=(\?|%3F)/g;
ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);

1753 1754 1755 1756 1757
tmp = new Array();
for(var i=0; i<2; i++)
    tmp[i] = /b/;
ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");

1758 1759 1760
ok(isNullBSTR(getNullBSTR()), "isNullBSTR(getNullBSTR()) failed\n");
ok(getNullBSTR() === '', "getNullBSTR() !== ''");
ok(+getNullBSTR() === 0 , "+getNullBTR() !=== 0");
1761

1762
ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1763
ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1764 1765 1766 1767 1768 1769 1770
ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
ok(nullDisp !== re, "nullDisp === re");
ok(nullDisp === null, "nullDisp === null");
ok(nullDisp == null, "nullDisp == null");
ok(getVT(true && nullDisp) === "VT_DISPATCH",
   "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1771
ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1772 1773
ok(nullDisp != new Object(), "nullDisp == new Object()");
ok(new Object() != nullDisp, "new Object() == nullDisp");
1774 1775 1776 1777 1778
ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
tmp = getVT(Object(nullDisp));
ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
tmp = Object(nullDisp).toString();
ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1779

1780
function do_test() {}
1781 1782
function nosemicolon() {} nosemicolon();
function () {} nosemicolon();
1783

1784 1785 1786 1787 1788 1789
if(false) {
    function in_if_false() { return true; } ok(false, "!?");
}

ok(in_if_false(), "in_if_false failed");

1790 1791 1792
(function() { newValue = 1; })();
ok(newValue === 1, "newValue = " + newValue);

1793 1794
obj = {undefined: 3};

1795 1796 1797 1798 1799 1800
ok(typeof(name_override_func) === "function", "typeof(name_override_func) = " + typeof(name_override_func));
name_override_func = 3;
ok(name_override_func === 3, "name_override_func = " + name_override_func);
function name_override_func() {};
ok(name_override_func === 3, "name_override_func = " + name_override_func);

1801 1802 1803 1804 1805 1806 1807
tmp = (function() {
    var ret = false;
    with({ret: true})
        return ret;
})();
ok(tmp, "tmp = " + tmp);

1808 1809 1810 1811 1812 1813 1814 1815 1816
tmp = (function() {
    for(var iter in [1,2,3,4]) {
        var ret = false;
        with({ret: true})
            return ret;
    }
})();
ok(tmp, "tmp = " + tmp);

1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834
(function() {
    ok(typeof(func) === "function", "typeof(func)  = " + typeof(func));
    with(new Object()) {
        var x = false && function func() {};
    }
    ok(typeof(func) === "function", "typeof(func)  = " + typeof(func));
})();

(function() {
    ok(x === undefined, "x = " + x); // x is declared, but never initialized
    with({x: 1}) {
        ok(x === 1, "x = " + x);
        var x = 2;
        ok(x === 2, "x = " + x);
    }
    ok(x === undefined, "x = " + x);
})();

1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851
/* NoNewline rule parser tests */
while(true) {
    if(true) break
    tmp = false
}

while(true) {
    if(true) break /*
                    * no semicolon, but comment present */
    tmp = false
}

while(true) {
    if(true) break // no semicolon, but comment present
    tmp = false
}

1852 1853 1854 1855 1856 1857
while(true) {
    break
    continue
    tmp = false
}

1858 1859 1860 1861 1862 1863 1864
function returnTest() {
    return
    true;
}

ok(returnTest() === undefined, "returnTest = " + returnTest());

1865 1866 1867
ActiveXObject = 1;
ok(ActiveXObject === 1, "ActiveXObject = " + ActiveXObject);

1868 1869 1870
Boolean = 1;
ok(Boolean === 1, "Boolean = " + Boolean);

1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882
Object = 1;
ok(Object === 1, "Object = " + Object);

Array = 1;
ok(Array === 1, "Array = " + Array);

Date = 1;
ok(Date === 1, "Date = " + Date);

Error = 1;
ok(Error === 1, "Error = " + Error);

1883 1884 1885 1886
/* Keep this test in the end of file */
undefined = 6;
ok(undefined === 6, "undefined = " + undefined);

1887 1888 1889 1890 1891 1892 1893 1894 1895
NaN = 6;
ok(NaN === 6, "NaN !== 6");

Infinity = 6;
ok(Infinity === 6, "Infinity !== 6");

Math = 6;
ok(Math === 6, "NaN !== 6");

1896
reportSuccess();