michael@0: function thrower1(x) { michael@0: throw x + 2; michael@0: michael@0: // Dead code, should be ignored. michael@0: throw ++x; michael@0: return x; michael@0: } michael@0: function test1() { michael@0: // If we ever inline functions containing JSOP_THROW, michael@0: // this shouldn't assert. michael@0: function f(x) { michael@0: thrower1(x + 1); michael@0: } michael@0: for (var i=0; i<11000; i++) { michael@0: try { michael@0: f(i); michael@0: assertEq(0, 1); michael@0: } catch(e) { michael@0: assertEq(e, i + 3); michael@0: } michael@0: } michael@0: } michael@0: test1(); michael@0: michael@0: // Test throwing from an uncompilable (interpreted) function. michael@0: function getException(f) { michael@0: try { michael@0: f(); michael@0: assertEq(0, 1); michael@0: } catch(e) { michael@0: return e; michael@0: } michael@0: assertEq(0, 1); michael@0: } michael@0: michael@0: function thrower2(x) { michael@0: if (x > 90) michael@0: throw x; michael@0: with ({}) {}; // Abort compilation...(?) michael@0: } michael@0: function test2() { michael@0: for (var i = 0; i < 100; i++) { michael@0: thrower2(i); michael@0: } michael@0: } michael@0: assertEq(getException(test2), 91); michael@0: michael@0: // Throwing |this| from a constructor. michael@0: function thrower3(x) { michael@0: this.x = x; michael@0: if (x > 90) michael@0: throw this; michael@0: } michael@0: function test3() { michael@0: for (var i=0; i < 100; i++) { michael@0: new thrower3(i); michael@0: } michael@0: } michael@0: assertEq(getException(test3).x, 91); michael@0: michael@0: // Throwing an exception in various loop blocks. michael@0: var count = 0; michael@0: function thrower4(x) { michael@0: throw count++; michael@0: count += 12345; // Shouldn't be executed. michael@0: } michael@0: function test4_1() { michael@0: var i = 0; michael@0: for (new thrower4(i); i < 100; i++) { michael@0: count += 2000; // Shouldn't be executed. michael@0: } michael@0: } michael@0: function test4_2() { michael@0: for (var i = 0; thrower4(i); i++) { michael@0: count += 3000; // Shouldn't be executed. michael@0: } michael@0: } michael@0: function test4_3() { michael@0: for (var i = 0; i < 100; thrower4(i)) { michael@0: count += 5; michael@0: } michael@0: } michael@0: function test4_4() { michael@0: for (var i = 0; i < 10; i++) { michael@0: if (i > 8) michael@0: thrower4(); michael@0: count += i; michael@0: } michael@0: } michael@0: for (var i = 0; i < 100; i++) { michael@0: assertEq(getException(test4_1), count-1); michael@0: assertEq(getException(test4_2), count-1); michael@0: assertEq(getException(test4_3), count-1); michael@0: assertEq(getException(test4_4), count-1); michael@0: } michael@0: assertEq(count, 4500);