Bug 787309 - Fallback on try notes after continuing on a goto. r=luke
authorNicolas B. Pierron <nicolas.b.pierron@mozilla.com>
Sat, 29 Sep 2012 00:43:20 -0700
changeset 108728 9f22813d133f4b93717e07569a37c2c3f1643a34
parent 108727 81b8598fb470d41430eb71767d292dbbb055e03f
child 108729 57e4febd27752f055ce632a30af0b610c9016237
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersluke
bugs787309
milestone18.0a1
Bug 787309 - Fallback on try notes after continuing on a goto. r=luke
js/src/jit-test/tests/basic/bug787309.js
js/src/jsopcode.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/bug787309.js
@@ -0,0 +1,7 @@
+// |jit-test| error: TypeError
+try {
+    h
+} catch (x
+if gc()) {} finally {
+    this.z.z
+}
--- a/js/src/jsopcode.cpp
+++ b/js/src/jsopcode.cpp
@@ -6432,16 +6432,37 @@ ReconstructPCStack(JSContext *cx, JSScri
                 pc += jmpoff;
                 oplen = 0;
                 if (hpcdepth != unsigned(-1)) {
                     pcdepth = hpcdepth;
                     hpcdepth = unsigned(-1);
                 }
                 continue;
             }
+
+            if (!script->hasTrynotes())
+                continue;
+
+            // If we do not follow a goto we look for another mean to continue
+            // at the next PC.
+            JSTryNote *tn = script->trynotes()->vector;
+            JSTryNote *tnEnd = tn + script->trynotes()->length;
+            for (; tn != tnEnd; tn++) {
+                jsbytecode *start = script->main() + tn->start;
+                jsbytecode *end = start + tn->length;
+                if (start < pc && pc <= end && end <= target)
+                    break;
+            }
+            if (tn != tnEnd) {
+                pcdepth = tn->stackDepth;
+                hpcdepth = unsigned(-1);
+                oplen = 0;
+                pc = script->main() + tn->start + tn->length;
+            }
+            continue;
         }
 
         /*
          * A (C ? T : E) expression requires skipping either T (if target is in
          * E) or both T and E (if target is after the whole expression) before
          * adjusting pcdepth based on the JSOP_IFEQ at pc that tests condition
          * C. We know that the stack depth can't change from what it was with
          * C on top of stack.