Bug 677079 - Part t: Provide IsContextRunningJS in jsfriendapi.h; r=jorendorff
authorMs2ger <ms2ger@gmail.com>
Sun, 15 Jan 2012 09:13:10 +0100
changeset 85697 c8ba49dafe5e2fad9822ec590cdb3a486113410b
parent 85696 346328bd1f2e11bf41c7ab6fba3f0085f59b108f
child 85698 d848942fc440ea80308708045d32846e5c8bd3e3
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs677079
milestone12.0a1
Bug 677079 - Part t: Provide IsContextRunningJS in jsfriendapi.h; r=jorendorff
js/src/jsfriendapi.cpp
js/src/jsfriendapi.h
js/xpconnect/src/nsXPConnect.cpp
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -574,9 +574,16 @@ HasUnrootedGlobal(const JSContext *cx)
 }
 
 JS_FRIEND_API(void)
 SetActivityCallback(JSRuntime *rt, ActivityCallback cb, void *arg)
 {
     rt->activityCallback = cb;
     rt->activityCallbackArg = arg;
 }
+
+JS_FRIEND_API(bool)
+IsContextRunningJS(JSContext *cx)
+{
+    return !cx->stack.empty();
+}
+
 } // namespace js
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -530,16 +530,19 @@ 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);
 
+extern JS_FRIEND_API(bool)
+IsContextRunningJS(JSContext *cx);
+
 } /* 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,
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -64,17 +64,17 @@
 #include "XPCQuickStubs.h"
 #include "dombindings.h"
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Base64.h"
 
 #include "nsWrapperCacheInlines.h"
 
-#include "jscntxt.h" // context->stackLimit, sizeof(JSContext), js::CompartmentVector, cx->stack.empty()
+#include "jscntxt.h" // context->stackLimit, sizeof(JSContext), js::CompartmentVector
 
 NS_IMPL_THREADSAFE_ISUPPORTS7(nsXPConnect,
                               nsIXPConnect,
                               nsISupportsWeakReference,
                               nsIThreadObserver,
                               nsIJSRuntimeService,
                               nsIJSContextStack,
                               nsIThreadJSContextStack,
@@ -2600,17 +2600,17 @@ nsXPConnect::Push(JSContext * cx)
          const InfallibleTArray<XPCJSContextInfo>* stack = data->GetJSContextStack()->GetStack();
          if (!gDesiredDebugMode) {
              /* Turn off debug mode immediately, even if JS code is currently running */
              CheckForDebugMode(mRuntime->GetJSRuntime());
          } else {
              bool runningJS = false;
              for (PRUint32 i = 0; i < stack->Length(); ++i) {
                  JSContext *cx = (*stack)[i].cx;
-                 if (cx && !cx->stack.empty()) {
+                 if (cx && js::IsContextRunningJS(cx)) {
                      runningJS = true;
                      break;
                  }
              }
              if (!runningJS)
                  CheckForDebugMode(mRuntime->GetJSRuntime());
          }
      }