summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/throw.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/jit-test/tests/ion/throw.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jit-test/tests/ion/throw.js')
-rw-r--r--js/src/jit-test/tests/ion/throw.js111
1 files changed, 111 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/ion/throw.js b/js/src/jit-test/tests/ion/throw.js
new file mode 100644
index 000000000..808345f88
--- /dev/null
+++ b/js/src/jit-test/tests/ion/throw.js
@@ -0,0 +1,111 @@
+function thrower1(x) {
+ throw x + 2;
+
+ // Dead code, should be ignored.
+ throw ++x;
+ return x;
+}
+function test1() {
+ // If we ever inline functions containing JSOP_THROW,
+ // this shouldn't assert.
+ function f(x) {
+ thrower1(x + 1);
+ }
+ for (var i=0; i<11000; i++) {
+ try {
+ f(i);
+ assertEq(0, 1);
+ } catch(e) {
+ assertEq(e, i + 3);
+ }
+ }
+}
+test1();
+
+// Test throwing from an uncompilable (interpreted) function.
+function getException(f) {
+ try {
+ f();
+ assertEq(0, 1);
+ } catch(e) {
+ return e;
+ }
+ assertEq(0, 1);
+}
+
+function thrower2(x) {
+ if (x > 90)
+ throw x;
+ with ({}) {}; // Abort compilation...(?)
+}
+function test2() {
+ for (var i = 0; i < 100; i++) {
+ thrower2(i);
+ }
+}
+assertEq(getException(test2), 91);
+
+// Throwing |this| from a constructor.
+function thrower3(x) {
+ this.x = x;
+ if (x > 90)
+ throw this;
+}
+function test3() {
+ for (var i=0; i < 100; i++) {
+ new thrower3(i);
+ }
+}
+assertEq(getException(test3).x, 91);
+
+// Throwing an exception in various loop blocks.
+var count = 0;
+function thrower4(x) {
+ throw count++;
+ count += 12345; // Shouldn't be executed.
+}
+function test4_1() {
+ var i = 0;
+ for (new thrower4(i); i < 100; i++) {
+ count += 2000; // Shouldn't be executed.
+ }
+}
+function test4_2() {
+ for (var i = 0; thrower4(i); i++) {
+ count += 3000; // Shouldn't be executed.
+ }
+}
+function test4_3() {
+ for (var i = 0; i < 100; thrower4(i)) {
+ count += 5;
+ }
+}
+function test4_4() {
+ for (var i = 0; i < 10; i++) {
+ if (i > 8)
+ thrower4();
+ count += i;
+ }
+}
+for (var i = 0; i < 100; i++) {
+ assertEq(getException(test4_1), count-1);
+ assertEq(getException(test4_2), count-1);
+ assertEq(getException(test4_3), count-1);
+ assertEq(getException(test4_4), count-1);
+}
+assertEq(count, 4500);
+
+function test5() {
+ var res = 0;
+ for (var i=0; i<40; i++) {
+ try {
+ throw i;
+ } catch (e if e % 2) {
+ res += e;
+ } catch (e) {
+ res += e * 3;
+ }
+ }
+ return res;
+}
+assertEq(test5(), 1540);