Bug 1414442 - De-COM nsIXPConnect::CurrentJSStack. r=mrbkap draft
authorAndrew McCreight <continuation@gmail.com>
Fri, 03 Nov 2017 11:59:04 -0700
changeset 695049 e9a810abf91ef8bc66a86698d81bc9738862aadd
parent 695048 75c04adb414bc00d39a0af80691a82af1ceebbd0
child 695050 33eaf4552d32d2064f0f98fb01831d6abe4a9270
push id88322
push userbmo:continuation@gmail.com
push dateWed, 08 Nov 2017 17:55:46 +0000
reviewersmrbkap
bugs1414442
milestone58.0a1
Bug 1414442 - De-COM nsIXPConnect::CurrentJSStack. r=mrbkap MozReview-Commit-ID: 6r35y1MJ0v2
js/xpconnect/idl/nsIXPConnect.idl
js/xpconnect/src/Sandbox.cpp
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/nsXPConnect.cpp
--- a/js/xpconnect/idl/nsIXPConnect.idl
+++ b/js/xpconnect/idl/nsIXPConnect.idl
@@ -370,19 +370,16 @@ interface nsIXPConnect : nsISupports
     /**
     * This only succeeds if the JSObject is a nsIXPConnectWrappedNative.
     * A new wrapper is *never* constructed.
     */
     nsIXPConnectWrappedNative
     getWrappedNativeOfJSObject(in JSContextPtr aJSContext,
                                in JSObjectPtr  aJSObj);
 
-    // Will return null if there is no JS stack right now.
-    readonly attribute nsIStackFrame                CurrentJSStack;
-
     void debugDump(in short depth);
     void debugDumpObject(in nsISupports aCOMObj, in short depth);
     void debugDumpJSStack(in boolean showArgs,
                           in boolean showLocals,
                           in boolean showThisProps);
 
     /**
     * wrapJSAggregatedToNative is just like wrapJS except it is used in cases
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -1721,18 +1721,17 @@ AssembleSandboxMemoryReporterName(JSCont
         return NS_OK;
 #endif
 
     // Get the xpconnect native call context.
     XPCCallContext* cc = XPCJSContext::Get()->GetCallContext();
     NS_ENSURE_TRUE(cc, NS_ERROR_INVALID_ARG);
 
     // Get the current source info from xpc.
-    nsCOMPtr<nsIStackFrame> frame;
-    nsXPConnect::XPConnect()->GetCurrentJSStack(getter_AddRefs(frame));
+    nsCOMPtr<nsIStackFrame> frame = dom::GetCurrentJSStack();
 
     // Append the caller's location information.
     if (frame) {
         nsString location;
         int32_t lineNumber = 0;
         frame->GetFilename(cx, location);
         frame->GetLineNumber(cx, &lineNumber);
 
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -2230,23 +2230,18 @@ nsXPCComponents_Utils::EvalInSandbox(con
     }
 
     // Optional fourth and fifth arguments: filename and line number.
     int32_t lineNo = (optionalArgc >= 3) ? lineNumber : 1;
     nsCString filename;
     if (!filenameArg.IsVoid()) {
         filename.Assign(filenameArg);
     } else {
-        // Get the current source info from xpc.
-        nsresult rv;
-        nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        nsCOMPtr<nsIStackFrame> frame;
-        xpc->GetCurrentJSStack(getter_AddRefs(frame));
+        // Get the current source info.
+        nsCOMPtr<nsIStackFrame> frame = dom::GetCurrentJSStack();
         if (frame) {
             nsString frameFile;
             frame->GetFilename(cx, frameFile);
             CopyUTF16toUTF8(frameFile, filename);
             frame->GetLineNumber(cx, &lineNo);
         }
     }
 
@@ -3289,22 +3284,21 @@ XPC_IMPL_GET_OBJ_METHOD(nsXPCComponents,
 NS_IMETHODIMP
 nsXPCComponentsBase::IsSuccessCode(nsresult result, bool* out)
 {
     *out = NS_SUCCEEDED(result);
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsXPCComponents::GetStack(nsIStackFrame * *aStack)
+nsXPCComponents::GetStack(nsIStackFrame** aStack)
 {
-    nsresult rv;
-    nsXPConnect* xpc = nsXPConnect::XPConnect();
-    rv = xpc->GetCurrentJSStack(aStack);
-    return rv;
+    nsCOMPtr<nsIStackFrame> frame = dom::GetCurrentJSStack();
+    frame.forget(aStack);
+    return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXPCComponents::GetManager(nsIComponentManager * *aManager)
 {
     MOZ_ASSERT(aManager, "bad param");
     return NS_GetComponentManager(aManager);
 }
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -798,27 +798,16 @@ nsXPConnect::GetWrappedNativeOfNativeObj
     nsresult rv = XPCWrappedNative::GetUsedOnly(aCOMObj, scope, iface, &wrapper);
     if (NS_FAILED(rv))
         return NS_ERROR_FAILURE;
     *_retval = static_cast<nsIXPConnectWrappedNative*>(wrapper);
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsXPConnect::GetCurrentJSStack(nsIStackFrame * *aCurrentJSStack)
-{
-    MOZ_ASSERT(aCurrentJSStack, "bad param");
-
-    nsCOMPtr<nsIStackFrame> currentStack = dom::GetCurrentJSStack();
-    currentStack.forget(aCurrentJSStack);
-
-    return NS_OK;
-}
-
-NS_IMETHODIMP
 nsXPConnect::SetFunctionThisTranslator(const nsIID & aIID,
                                        nsIXPCFunctionThisTranslator* aTranslator)
 {
     XPCJSRuntime* rt = GetRuntimeInstance();
     IID2ThisTranslatorMap* map = rt->GetThisTranslatorMap();
     map->Add(aIID, aTranslator);
     return NS_OK;
 }