Bug 677079 - Part h: Expose debuggerHandler in jsfriendapi.h; r=igor
authorMs2ger <ms2ger@gmail.com>
Sun, 15 Jan 2012 09:13:09 +0100
changeset 86902 2b2c3d92ae9f5fe44f41da077db23cc8cec6ab0a
parent 86901 58eef6ad44addac145082de0c48fce67e6f1feea
child 86903 f9fe45249420b8b0b0d216cc57e40498f866b726
push idunknown
push userunknown
push dateunknown
reviewersigor
bugs677079
milestone12.0a1
Bug 677079 - Part h: Expose debuggerHandler in jsfriendapi.h; r=igor
dom/base/nsJSEnvironment.cpp
js/src/jsfriendapi.cpp
js/src/jsfriendapi.h
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -32,17 +32,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "jscntxt.h"
+#include "jscntxt.h" // outstandingRequests
 #include "nsJSEnvironment.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIDOMChromeWindow.h"
 #include "nsPIDOMWindow.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsDOMCID.h"
 #include "nsIServiceManager.h"
@@ -707,18 +707,17 @@ nsJSContext::DOMOperationCallback(JSCont
   // If we get here we're most likely executing an infinite loop in JS,
   // we'll tell the user about this and we'll give the user the option
   // of stopping the execution of the script.
   nsCOMPtr<nsIPrompt> prompt = GetPromptFromContext(ctx);
   NS_ENSURE_TRUE(prompt, JS_FALSE);
 
   // Check if we should offer the option to debug
   JSStackFrame* fp = ::JS_GetScriptedCaller(cx, NULL);
-  bool debugPossible = (fp != nsnull && cx->debugHooks &&
-                          cx->debugHooks->debuggerHandler != nsnull);
+  bool debugPossible = fp && js::CanCallContextDebugHandler(cx);
 #ifdef MOZ_JSDEBUGGER
   // Get the debugger service if necessary.
   if (debugPossible) {
     bool jsds_IsOn = false;
     const char jsdServiceCtrID[] = "@mozilla.org/js/jsd/debugger-service;1";
     nsCOMPtr<jsdIExecutionHook> jsdHook;
     nsCOMPtr<jsdIDebuggerService> jsds = do_GetService(jsdServiceCtrID, &rv);
 
@@ -837,20 +836,17 @@ nsJSContext::DOMOperationCallback(JSCont
     }
 
     ctx->mOperationCallbackTime = PR_Now();
     return JS_TRUE;
   }
   else if ((buttonPressed == 2) && debugPossible) {
     // Debug the script
     jsval rval;
-    switch(cx->debugHooks->debuggerHandler(cx, script, ::JS_GetFramePC(cx, fp),
-                                           &rval,
-                                           cx->debugHooks->
-                                           debuggerHandlerData)) {
+    switch (js::CallContextDebugHandler(cx, script, JS_GetFramePC(cx, fp), &rval)) {
       case JSTRAP_RETURN:
         JS_SetFrameReturnValue(cx, fp, rval);
         return JS_TRUE;
       case JSTRAP_ERROR:
         JS_ClearPendingException(cx);
         return JS_FALSE;
       case JSTRAP_THROW:
         JS_SetPendingException(cx, rval);
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -500,16 +500,32 @@ GetContextStructuredCloneCallbacks(JSCon
 
 JS_FRIEND_API(JSVersion)
 VersionSetXML(JSVersion version, bool enable)
 {
     return enable ? JSVersion(uint32_t(version) | VersionFlags::HAS_XML)
                   : JSVersion(uint32_t(version) & ~VersionFlags::HAS_XML);
 }
 
+JS_FRIEND_API(bool)
+CanCallContextDebugHandler(JSContext *cx)
+{
+    return cx->debugHooks && cx->debugHooks->debuggerHandler;
+}
+
+JS_FRIEND_API(JSTrapStatus)
+CallContextDebugHandler(JSContext *cx, JSScript *script, jsbytecode *bc, Value *rval)
+{
+    if (!CanCallContextDebugHandler(cx))
+        return JSTRAP_RETURN;
+
+    return cx->debugHooks->debuggerHandler(cx, script, bc, rval,
+                                           cx->debugHooks->debuggerHandlerData);
+}
+
 #ifdef JS_THREADSAFE
 JSThread *
 GetContextThread(const JSContext *cx)
 {
     return cx->thread();
 }
 #endif
 
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -487,16 +487,22 @@ class JS_FRIEND_API(AutoLockGC)
 };
 
 extern JS_FRIEND_API(const JSStructuredCloneCallbacks *)
 GetContextStructuredCloneCallbacks(JSContext *cx);
 
 extern JS_FRIEND_API(JSVersion)
 VersionSetXML(JSVersion version, bool enable);
 
+extern JS_FRIEND_API(bool)
+CanCallContextDebugHandler(JSContext *cx);
+
+extern JS_FRIEND_API(JSTrapStatus)
+CallContextDebugHandler(JSContext *cx, JSScript *script, jsbytecode *bc, Value *rval);
+
 } /* namespace js */
 
 /*
  * If protoKey is not JSProto_Null, then clasp is ignored. If protoKey is
  * JSProto_Null, clasp must non-null.
  */
 extern JS_FRIEND_API(JSBool)
 js_GetClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey,