Bug 677371 - [jsdbg2] Assertion failure: throwing, at jscntxt.h:1274. r=jimb
authorJason Orendorff <jorendorff@mozilla.com>
Tue, 09 Aug 2011 18:01:38 -0500
changeset 75238 48e43edc8834bc40875b3d82844ecf719c8d5c9c
parent 75237 bc955352f821f3bb9553d5e955455ef6d027d5d4
child 75239 deb37693a3661ad3b3b55ee715a6255c22e92241
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewersjimb
bugs677371
milestone8.0a1
Bug 677371 - [jsdbg2] Assertion failure: throwing, at jscntxt.h:1274. r=jimb
js/src/jit-test/tests/debug/onExceptionUnwind-07.js
js/src/methodjit/InvokeHelpers.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/onExceptionUnwind-07.js
@@ -0,0 +1,15 @@
+// Unwinding due to uncatchable errors does not trigger onExceptionUnwind.
+
+var g = newGlobal('new-compartment');
+var dbg = Debugger(g);
+var hits = 0;
+dbg.onExceptionUnwind = function (frame, value) { hits = 'BAD'; };
+dbg.onDebuggerStatement = function (frame) {
+    if (hits++ === 0)
+	assertEq(frame.eval("debugger;"), null);
+    else
+	return null;
+}
+
+assertEq(g.eval("debugger; 2"), 2);
+assertEq(hits, 2);
--- a/js/src/methodjit/InvokeHelpers.cpp
+++ b/js/src/methodjit/InvokeHelpers.cpp
@@ -461,42 +461,44 @@ js_InternalThrow(VMFrame &f)
         InlineReturn(f);
     }
 
     // Make sure sp is up to date.
     JS_ASSERT(&cx->regs() == &f.regs);
 
     jsbytecode *pc = NULL;
     for (;;) {
-        // Call the throw hook if necessary
-        JSThrowHook handler = cx->debugHooks->throwHook;
-        if (handler || !cx->compartment->getDebuggees().empty()) {
-            Value rval;
-            JSTrapStatus st = Debugger::onExceptionUnwind(cx, &rval);
-            if (st == JSTRAP_CONTINUE && handler) {
-                st = handler(cx, cx->fp()->script(), cx->regs().pc, Jsvalify(&rval),
-                             cx->debugHooks->throwHookData);
-            }
+        if (cx->isExceptionPending()) {
+            // Call the throw hook if necessary
+            JSThrowHook handler = cx->debugHooks->throwHook;
+            if (handler || !cx->compartment->getDebuggees().empty()) {
+                Value rval;
+                JSTrapStatus st = Debugger::onExceptionUnwind(cx, &rval);
+                if (st == JSTRAP_CONTINUE && handler) {
+                    st = handler(cx, cx->fp()->script(), cx->regs().pc, Jsvalify(&rval),
+                                 cx->debugHooks->throwHookData);
+                }
 
-            switch (st) {
-              case JSTRAP_ERROR:
-                cx->clearPendingException();
-                return NULL;
+                switch (st) {
+                case JSTRAP_ERROR:
+                    cx->clearPendingException();
+                    return NULL;
 
-              case JSTRAP_RETURN:
-                cx->clearPendingException();
-                cx->fp()->setReturnValue(rval);
-                return cx->jaegerCompartment()->forceReturnFromExternC();
+                case JSTRAP_RETURN:
+                    cx->clearPendingException();
+                    cx->fp()->setReturnValue(rval);
+                    return cx->jaegerCompartment()->forceReturnFromExternC();
 
-              case JSTRAP_THROW:
-                cx->setPendingException(rval);
-                break;
+                case JSTRAP_THROW:
+                    cx->setPendingException(rval);
+                    break;
 
-              default:
-                break;
+                default:
+                    break;
+                }
             }
         }
 
         pc = FindExceptionHandler(cx);
         if (pc)
             break;
 
         // The JIT guarantees that ScriptEpilogue() has always been run