michael@0: // Tests for IFEQX and GOTOX ops. michael@0: function testIfElse() { michael@0: var src = michael@0: "var a = 0;\n" + michael@0: "if (x) {\n"; michael@0: for (var i=0; i<7000; i++) { michael@0: src += "a = 1;"; michael@0: } michael@0: src += "} else {\n"; michael@0: for (var i=0; i<7000; i++) { michael@0: src += "a = 2;"; michael@0: } michael@0: src += "}\n"; michael@0: src += "return a;"; michael@0: michael@0: var f = new Function("x", src); michael@0: assertEq(f(true), 1); michael@0: assertEq(f(false), 2); michael@0: assertEq(f([1, 2, 3]), 1); michael@0: assertEq(f(), 2); michael@0: } michael@0: testIfElse(); michael@0: michael@0: function testWhile() { michael@0: var src = michael@0: "var i = 0, j = 0;\n" + michael@0: "while (i++ < 50) {\n"; michael@0: for (var i=0; i<5000; i++) { michael@0: src += "j = i;"; michael@0: } michael@0: src += "}\n"; michael@0: src += "return j;"; michael@0: michael@0: var f = new Function(src); michael@0: assertEq(f(), 50); michael@0: } michael@0: testWhile();