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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 function thrower1(x) {
michael@0 2 throw x + 2;
michael@0 3
michael@0 4 // Dead code, should be ignored.
michael@0 5 throw ++x;
michael@0 6 return x;
michael@0 7 }
michael@0 8 function test1() {
michael@0 9 // If we ever inline functions containing JSOP_THROW,
michael@0 10 // this shouldn't assert.
michael@0 11 function f(x) {
michael@0 12 thrower1(x + 1);
michael@0 13 }
michael@0 14 for (var i=0; i<11000; i++) {
michael@0 15 try {
michael@0 16 f(i);
michael@0 17 assertEq(0, 1);
michael@0 18 } catch(e) {
michael@0 19 assertEq(e, i + 3);
michael@0 20 }
michael@0 21 }
michael@0 22 }
michael@0 23 test1();
michael@0 24
michael@0 25 // Test throwing from an uncompilable (interpreted) function.
michael@0 26 function getException(f) {
michael@0 27 try {
michael@0 28 f();
michael@0 29 assertEq(0, 1);
michael@0 30 } catch(e) {
michael@0 31 return e;
michael@0 32 }
michael@0 33 assertEq(0, 1);
michael@0 34 }
michael@0 35
michael@0 36 function thrower2(x) {
michael@0 37 if (x > 90)
michael@0 38 throw x;
michael@0 39 with ({}) {}; // Abort compilation...(?)
michael@0 40 }
michael@0 41 function test2() {
michael@0 42 for (var i = 0; i < 100; i++) {
michael@0 43 thrower2(i);
michael@0 44 }
michael@0 45 }
michael@0 46 assertEq(getException(test2), 91);
michael@0 47
michael@0 48 // Throwing |this| from a constructor.
michael@0 49 function thrower3(x) {
michael@0 50 this.x = x;
michael@0 51 if (x > 90)
michael@0 52 throw this;
michael@0 53 }
michael@0 54 function test3() {
michael@0 55 for (var i=0; i < 100; i++) {
michael@0 56 new thrower3(i);
michael@0 57 }
michael@0 58 }
michael@0 59 assertEq(getException(test3).x, 91);
michael@0 60
michael@0 61 // Throwing an exception in various loop blocks.
michael@0 62 var count = 0;
michael@0 63 function thrower4(x) {
michael@0 64 throw count++;
michael@0 65 count += 12345; // Shouldn't be executed.
michael@0 66 }
michael@0 67 function test4_1() {
michael@0 68 var i = 0;
michael@0 69 for (new thrower4(i); i < 100; i++) {
michael@0 70 count += 2000; // Shouldn't be executed.
michael@0 71 }
michael@0 72 }
michael@0 73 function test4_2() {
michael@0 74 for (var i = 0; thrower4(i); i++) {
michael@0 75 count += 3000; // Shouldn't be executed.
michael@0 76 }
michael@0 77 }
michael@0 78 function test4_3() {
michael@0 79 for (var i = 0; i < 100; thrower4(i)) {
michael@0 80 count += 5;
michael@0 81 }
michael@0 82 }
michael@0 83 function test4_4() {
michael@0 84 for (var i = 0; i < 10; i++) {
michael@0 85 if (i > 8)
michael@0 86 thrower4();
michael@0 87 count += i;
michael@0 88 }
michael@0 89 }
michael@0 90 for (var i = 0; i < 100; i++) {
michael@0 91 assertEq(getException(test4_1), count-1);
michael@0 92 assertEq(getException(test4_2), count-1);
michael@0 93 assertEq(getException(test4_3), count-1);
michael@0 94 assertEq(getException(test4_4), count-1);
michael@0 95 }
michael@0 96 assertEq(count, 4500);

mercurial