Bug 716167 - Add a release-mode assertion that XPConnect is never used off the main thread. r=mrbkap
authorBobby Holley <bobbyholley@gmail.com>
Sat, 14 Jan 2012 10:31:19 -0800
changeset 85728 ed73f7ef3e7d39b8879b15d219b6bc04b18f9239
parent 85727 a0e3fb36fb1acb91155aa0193263c1e142a69df4
child 85729 f295de5da279a6629d913b4b3e984c56b93b8890
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)
reviewersmrbkap
bugs716167
milestone12.0a1
Bug 716167 - Add a release-mode assertion that XPConnect is never used off the main thread. r=mrbkap
js/xpconnect/src/nsXPConnect.cpp
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -164,16 +164,22 @@ nsXPConnect::~nsXPConnect()
     gSelf = nsnull;
     gOnceAliveNowDead = true;
 }
 
 // static
 nsXPConnect*
 nsXPConnect::GetXPConnect()
 {
+    // Do a release-mode assert that we're not doing anything significant in
+    // XPConnect off the main thread. If you're an extension developer hitting
+    // this, you need to change your code. See bug 716167.
+    if (!NS_LIKELY(NS_IsMainThread() || NS_IsCycleCollectorThread()))
+        JS_Assert("NS_IsMainThread()", __FILE__, __LINE__);
+
     if (!gSelf) {
         if (gOnceAliveNowDead)
             return nsnull;
         gSelf = new nsXPConnect();
         if (!gSelf)
             return nsnull;
 
         if (!gSelf->mRuntime) {
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -3646,16 +3646,22 @@ private:
 class XPCPerThreadData
 {
     typedef mozilla::Mutex Mutex;
 
 public:
     // Get the instance of this object for the current thread
     static inline XPCPerThreadData* GetData(JSContext *cx)
     {
+        // Do a release-mode assert that we're not doing anything significant in
+        // XPConnect off the main thread. If you're an extension developer hitting
+        // this, you need to change your code. See bug 716167.
+        if (!NS_LIKELY(NS_IsMainThread() || NS_IsCycleCollectorThread()))
+            JS_Assert("NS_IsMainThread()", __FILE__, __LINE__);
+
         if (cx) {
             NS_ASSERTION(js::GetContextThread(cx), "Uh, JS context w/o a thread?");
 
             if (js::GetContextThread(cx) == sMainJSThread)
                 return sMainThreadData;
         } else if (sMainThreadData && sMainThreadData->mThread == PR_GetCurrentThread()) {
             return sMainThreadData;
         }