Commits

Andrew Sutherland committed ce7a791

it works! although we may have added a new form of corruption now :)

  • Participants
  • Parent commits 1ec903e

Comments (0)

Files changed (4)

File jetpack-scriptcontext-naked-jscontext

+# HG changeset patch
+# Parent 9af83a523235c7ec4adfd6d7e75815c5f419521c
+
+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;

File jetpack-scriptcontext-problem-snafu

+# HG changeset patch
+# Parent 9af83a523235c7ec4adfd6d7e75815c5f419521c
+
+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,7 @@
+ 
+ private:
+     typedef nsInterfaceHashtable<nsUint32HashKey, nsIProbeMessageListener> ListenerMap;
+-    typedef nsInterfaceHashtable<nsUint32HashKey, nsIScriptContext> ContextMap;
++    typedef nsInterfaceHashtable<nsUint32HashKey, nsISupports> ContextMap;
+ 
+     bool mHasShutdown;
+     nsCOMPtr<nsITimer> mDrainTimer;
+@@ -242,8 +242,15 @@
+ 
+     /* lookup listener for this scriptcookie */
+     nsCOMPtr<nsIProbeMessageListener> listener = mListeners.Get(cookie);
+-    nsCOMPtr<nsIScriptContext> scriptCx = mListenerContexts.Get(cookie);
+-    JSContext *cx = (JSContext *) scriptCx->GetNativeContext();
++    nsCOMPtr<nsISupports> supportsCx = mListenerContexts.Get(cookie);
++    nsCOMPtr<nsIScriptContext> scriptCx = do_QueryInterface(supportsCx);
++    JSContext *cx;
++    if (scriptCx) {
++        cx = (JSContext *) scriptCx->GetNativeContext();
++    }
++    else {
++        nsCOMPtr<ns
++    }
+ 
+     /* unpack message, using cx */
+     ScriptCookie outCookie;
+@@ -395,9 +402,10 @@
+     if (!mManager->runScriptOnce(codeDesc, &codeCookie))
+         return NS_ERROR_FAILURE;
+ 
+-    nsIScriptContext *scriptCx = GetScriptContextFromJSContext(cx);
+-    if (!scriptCx)
+-        return NS_ERROR_FAILURE;
++    if (!(JS_GetOptions(cx) & JSOPTION_PRIVATE_IS_NSISUPPORTS))
++        return NS_ERROR_UNEXPECTED;
++    nsISupports *supportsCx =
++        static_cast<nsISupports *>(JS_GetContextPrivate(cx));
+ 
+     mListeners.Put(codeCookie, listener);
+     mListenerContexts.Put(codeCookie, scriptCx);

File provide-all-compartment-ptrs

+# HG changeset patch
+# Parent dab5ad4034f71d0c71a7f5136616f8016a613f35
+
+diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp
+--- a/js/xpconnect/src/XPCJSRuntime.cpp
++++ b/js/xpconnect/src/XPCJSRuntime.cpp
+@@ -1249,12 +1249,12 @@
+                     name->AppendLiteral(", ");
+                     name->Append(compartmentPrivate->location);
+                 }
++            }
+ 
+-                // ample; 64-bit address max is 18 chars
+-                static const int maxLength = 31;
+-                nsPrintfCString address(maxLength, ", 0x%llx", PRUint64(c));
+-                name->Append(address);
+-            }
++            // ample; 64-bit address max is 18 chars
++            static const int maxLength = 31;
++            nsPrintfCString address(maxLength, ", 0x%llx", PRUint64(c));
++            name->Append(address);
+ 
+             // A hack: replace forward slashes with '\\' so they aren't
+             // treated as path separators.  Users of the reporters
 xpcom-nsIProbeService
 js-runtime-fixups
 js-run-probes
+provide-all-compartment-ptrs
+jetpack-scriptcontext-naked-jscontext
+jetpack-scriptcontext-problem-snafu