js/src/jit-test/tests/ion/throw.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/ion/throw.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +function thrower1(x) {
     1.5 +    throw x + 2;
     1.6 +
     1.7 +    // Dead code, should be ignored.
     1.8 +    throw ++x;
     1.9 +    return x;
    1.10 +}
    1.11 +function test1() {
    1.12 +    // If we ever inline functions containing JSOP_THROW,
    1.13 +    // this shouldn't assert.
    1.14 +    function f(x) {
    1.15 +        thrower1(x + 1);
    1.16 +    }
    1.17 +    for (var i=0; i<11000; i++) {
    1.18 +        try {
    1.19 +            f(i);
    1.20 +            assertEq(0, 1);
    1.21 +        } catch(e) {
    1.22 +            assertEq(e, i + 3);
    1.23 +        }
    1.24 +    }
    1.25 +}
    1.26 +test1();
    1.27 +
    1.28 +// Test throwing from an uncompilable (interpreted) function.
    1.29 +function getException(f) {
    1.30 +    try {
    1.31 +        f();
    1.32 +        assertEq(0, 1);
    1.33 +    } catch(e) {
    1.34 +        return e;
    1.35 +    }
    1.36 +    assertEq(0, 1);
    1.37 +}
    1.38 +
    1.39 +function thrower2(x) {
    1.40 +    if (x > 90)
    1.41 +        throw x;
    1.42 +    with ({}) {}; // Abort compilation...(?)
    1.43 +}
    1.44 +function test2() {
    1.45 +    for (var i = 0; i < 100; i++) {
    1.46 +        thrower2(i);
    1.47 +    }
    1.48 +}
    1.49 +assertEq(getException(test2), 91);
    1.50 +
    1.51 +// Throwing |this| from a constructor.
    1.52 +function thrower3(x) {
    1.53 +    this.x = x;
    1.54 +    if (x > 90)
    1.55 +        throw this;
    1.56 +}
    1.57 +function test3() {
    1.58 +    for (var i=0; i < 100; i++) {
    1.59 +        new thrower3(i);
    1.60 +    }
    1.61 +}
    1.62 +assertEq(getException(test3).x, 91);
    1.63 +
    1.64 +// Throwing an exception in various loop blocks.
    1.65 +var count = 0;
    1.66 +function thrower4(x) {
    1.67 +    throw count++;
    1.68 +    count += 12345; // Shouldn't be executed.
    1.69 +}
    1.70 +function test4_1() {
    1.71 +    var i = 0;
    1.72 +    for (new thrower4(i); i < 100; i++) {
    1.73 +        count += 2000; // Shouldn't be executed.
    1.74 +    }
    1.75 +}
    1.76 +function test4_2() {
    1.77 +    for (var i = 0; thrower4(i); i++) {
    1.78 +	count += 3000; // Shouldn't be executed.
    1.79 +    }
    1.80 +}
    1.81 +function test4_3() {
    1.82 +    for (var i = 0; i < 100; thrower4(i)) {
    1.83 +	count += 5;
    1.84 +    }
    1.85 +}
    1.86 +function test4_4() {
    1.87 +    for (var i = 0; i < 10; i++) {
    1.88 +        if (i > 8)
    1.89 +            thrower4();
    1.90 +        count += i;
    1.91 +    }
    1.92 +}
    1.93 +for (var i = 0; i < 100; i++) {
    1.94 +    assertEq(getException(test4_1), count-1);
    1.95 +    assertEq(getException(test4_2), count-1);
    1.96 +    assertEq(getException(test4_3), count-1);
    1.97 +    assertEq(getException(test4_4), count-1);
    1.98 +}
    1.99 +assertEq(count, 4500);

mercurial