Source

jsprobes-patches / jetpack-scriptcontext-naked-jscontext

# HG changeset patch
# Parent 6a8655ceb5021e8e16e59c277d2933d73195a97f

diff --git a/toolkit/components/probes/ProbeService.cpp b/toolkit/components/probes/ProbeService.cpp
--- a/toolkit/components/probes/ProbeService.cpp
+++ b/toolkit/components/probes/ProbeService.cpp
@@ -83,7 +83,18 @@
 
 private:
     typedef nsInterfaceHashtable<nsUint32HashKey, nsIProbeMessageListener> ListenerMap;
-    typedef nsInterfaceHashtable<nsUint32HashKey, nsIScriptContext> ContextMap;
+    // the basic idea is that we can hold naked JSContext pointers here because
+    //  we our ListenerMap will already be keeping the underlying JSContext
+    //  alive somehow.  We previously used nsIScriptContext, but in the case of
+    //  jetpack modules provided by XPConnect, there is no nsIScriptContext.
+    //  However, XPConnect does keep the JSContext alive for us.  Or at least
+    //  I hope.  For all I know right now, it could cycle through them nonstop
+    //  in order to trip up jerks like myself.
+    // All we really want from this is the ability to deserialize
+    //  representations into the right target compartment so we don't have
+    //  cross-compatment wrappers created needlessly.
+    // We do not want automatic deletion, so not an nsClassHashtable.
+    typedef nsDataHashtable<nsUint32HashKey, JSContext*> ContextMap;
 
     bool mHasShutdown;
     nsCOMPtr<nsITimer> mDrainTimer;
@@ -242,8 +253,7 @@
 
     /* lookup listener for this scriptcookie */
     nsCOMPtr<nsIProbeMessageListener> listener = mListeners.Get(cookie);
-    nsCOMPtr<nsIScriptContext> scriptCx = mListenerContexts.Get(cookie);
-    JSContext *cx = (JSContext *) scriptCx->GetNativeContext();
+    JSContext *cx = mListenerContexts.Get(cookie);
 
     /* unpack message, using cx */
     ScriptCookie outCookie;
@@ -395,12 +405,8 @@
     if (!mManager->runScriptOnce(codeDesc, &codeCookie))
         return NS_ERROR_FAILURE;
 
-    nsIScriptContext *scriptCx = GetScriptContextFromJSContext(cx);
-    if (!scriptCx)
-        return NS_ERROR_FAILURE;
-
     mListeners.Put(codeCookie, listener);
-    mListenerContexts.Put(codeCookie, scriptCx);
+    mListenerContexts.Put(codeCookie, cx);
     StartDrainTimer(400);
 
     return NS_OK;