Bug 886459, part 3 - Remove simple uses of nsIJSRuntimeService to get the JSRuntime. r=bholley

This commit is contained in:
Andrew McCreight 2015-06-26 18:44:14 -07:00
parent fd7600ed25
commit 10dd21a3ef
12 changed files with 28 additions and 91 deletions

View File

@ -1256,8 +1256,7 @@ nsresult nsScriptSecurityManager::Init()
//-- Register security check callback in the JS engine
// Currently this is used to control access to function.caller
rv = nsXPConnect::XPConnect()->GetRuntime(&sRuntime);
NS_ENSURE_SUCCESS(rv, rv);
sRuntime = xpc::GetJSRuntime();
static const JSSecurityCallbacks securityCallbacks = {
ContentSecurityPolicyPermitsJSAction,

View File

@ -26,7 +26,6 @@
#include "nsIMemoryReporter.h"
#include "nsIProtocolHandler.h"
#include "nsIScriptSecurityManager.h"
#include "nsIJSRuntimeService.h"
#include "nsIDOMClassInfo.h"
#include "xpcpublic.h"
#include "mozilla/CycleCollectedJSRuntime.h"
@ -1822,15 +1821,6 @@ nsMessageManagerScriptExecutor::InitChildGlobalInternal(
nsISupports* aScope,
const nsACString& aID)
{
nsCOMPtr<nsIJSRuntimeService> runtimeSvc =
do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
NS_ENSURE_TRUE(runtimeSvc, false);
JSRuntime* rt = nullptr;
runtimeSvc->GetRuntime(&rt);
NS_ENSURE_TRUE(rt, false);
AutoSafeJSContext cx;
nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal));

View File

@ -14,7 +14,6 @@
#include "nsDOMCID.h"
#include "nsIServiceManager.h"
#include "nsIXPConnect.h"
#include "nsIJSRuntimeService.h"
#include "nsCOMPtr.h"
#include "nsISupportsPrimitives.h"
#include "nsReadableUtils.h"
@ -197,11 +196,6 @@ static bool sDidPaintAfterPreviousICCSlice = false;
static nsScriptNameSpaceManager *gNameSpaceManager;
static nsIJSRuntimeService *sRuntimeService;
static const char kJSRuntimeServiceContractID[] =
"@mozilla.org/js/xpc/RuntimeService;1";
static PRTime sFirstCollectionTime;
static JSRuntime *sRuntime;
@ -651,10 +645,8 @@ nsJSContext::~nsJSContext()
if (!sContextCount && sDidShutdown) {
// The last context is being deleted, and we're already in the
// process of shutting down, release the JS runtime service, and
// the security manager.
// process of shutting down, release the security manager.
NS_IF_RELEASE(sRuntimeService);
NS_IF_RELEASE(sSecurityManager);
}
}
@ -2372,7 +2364,6 @@ mozilla::dom::StartupJSEnvironment()
sNeedsFullCC = false;
sNeedsGCAfterCC = false;
gNameSpaceManager = nullptr;
sRuntimeService = nullptr;
sRuntime = nullptr;
sIsInitialized = false;
sDidShutdown = false;
@ -2673,13 +2664,8 @@ nsJSContext::EnsureStatics()
MOZ_CRASH();
}
rv = CallGetService(kJSRuntimeServiceContractID, &sRuntimeService);
if (NS_FAILED(rv)) {
MOZ_CRASH();
}
rv = sRuntimeService->GetRuntime(&sRuntime);
if (NS_FAILED(rv)) {
sRuntime = xpc::GetJSRuntime();
if (!sRuntime) {
MOZ_CRASH();
}
@ -2850,9 +2836,7 @@ mozilla::dom::ShutdownJSEnvironment()
if (!sContextCount) {
// We're being shutdown, and there are no more contexts
// alive, release the JS runtime service and the security manager.
NS_IF_RELEASE(sRuntimeService);
// alive, release the security manager.
NS_IF_RELEASE(sSecurityManager);
}

View File

@ -12,6 +12,7 @@
#include "jsapi.h"
#include "jsfriendapi.h"
#include "xpcpublic.h"
#include "nsIUnicodeDecoder.h"
#include "nsIContent.h"
#include "nsJSUtils.h"
@ -19,7 +20,6 @@
#include "mozilla/dom/Element.h"
#include "nsGkAtoms.h"
#include "nsNetUtil.h"
#include "nsIJSRuntimeService.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "nsIScriptSecurityManager.h"
@ -831,12 +831,7 @@ NotifyOffThreadScriptLoadCompletedRunnable::Run()
// The result of the off thread parse was not actually needed to process
// the request (disappearing window, some other error, ...). Finish the
// request to avoid leaks in the JS engine.
nsCOMPtr<nsIJSRuntimeService> svc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
NS_ENSURE_TRUE(svc, NS_ERROR_FAILURE);
JSRuntime *rt;
svc->GetRuntime(&rt);
NS_ENSURE_TRUE(rt, NS_ERROR_FAILURE);
JS::FinishOffThreadScript(nullptr, rt, mToken);
JS::FinishOffThreadScript(nullptr, xpc::GetJSRuntime(), mToken);
}
return rv;

View File

@ -15,8 +15,8 @@
#include "mozilla/dom/ipc/BlobChild.h"
#include "mozilla/ipc/InputStreamUtils.h"
#include "nsIJSRuntimeService.h"
#include "nsPrintfCString.h"
#include "xpcpublic.h"
using namespace mozilla::ipc;
using namespace mozilla::jsipc;
@ -27,14 +27,7 @@ namespace dom {
PJavaScriptChild*
nsIContentChild::AllocPJavaScriptChild()
{
nsCOMPtr<nsIJSRuntimeService> svc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
NS_ENSURE_TRUE(svc, nullptr);
JSRuntime *rt;
svc->GetRuntime(&rt);
NS_ENSURE_TRUE(svc, nullptr);
return NewJavaScriptChild(rt);
return NewJavaScriptChild(xpc::GetJSRuntime());
}
bool

View File

@ -19,8 +19,8 @@
#include "mozilla/unused.h"
#include "nsFrameMessageManager.h"
#include "nsIJSRuntimeService.h"
#include "nsPrintfCString.h"
#include "xpcpublic.h"
using namespace mozilla::jsipc;
@ -49,15 +49,7 @@ nsIContentParent::AsContentParent()
PJavaScriptParent*
nsIContentParent::AllocPJavaScriptParent()
{
nsCOMPtr<nsIJSRuntimeService> svc =
do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
NS_ENSURE_TRUE(svc, nullptr);
JSRuntime *rt;
svc->GetRuntime(&rt);
NS_ENSURE_TRUE(svc, nullptr);
return NewJavaScriptParent(rt);
return NewJavaScriptParent(xpc::GetJSRuntime());
}
bool

View File

@ -40,7 +40,6 @@
#include "mozilla/EventStates.h"
#include "nsFocusManager.h"
#include "nsHTMLStyleSheet.h"
#include "nsIJSRuntimeService.h"
#include "nsNameSpaceManager.h"
#include "nsIObjectInputStream.h"
#include "nsIObjectOutputStream.h"
@ -2767,9 +2766,6 @@ NotifyOffThreadScriptCompletedRunnable::Run()
// Note: this unroots mScript so that it is available to be collected by the
// JS GC. The receiver needs to root the script before performing a call that
// could GC.
nsCOMPtr<nsIJSRuntimeService> svc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
NS_ENSURE_TRUE(svc, NS_ERROR_FAILURE);
JSScript *script;
{
AutoSafeJSContext cx;

View File

@ -26,7 +26,6 @@
#include "nsIChannel.h"
#include "nsIClassInfo.h"
#include "nsIDirectoryService.h"
#include "nsIJSRuntimeService.h"
#include "nsIPrincipal.h"
#include "nsIScriptSecurityManager.h"
#include "nsIURI.h"
@ -476,15 +475,8 @@ XPCShellEnvironment::Init()
// is unbuffered by default
setbuf(stdout, 0);
nsCOMPtr<nsIJSRuntimeService> rtsvc =
do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
if (!rtsvc) {
NS_ERROR("failed to get nsJSRuntimeService!");
return false;
}
JSRuntime *rt;
if (NS_FAILED(rtsvc->GetRuntime(&rt)) || !rt) {
JSRuntime *rt = xpc::GetJSRuntime();
if (!rt) {
NS_ERROR("failed to get JSRuntime from nsJSRuntimeService!");
return false;
}

View File

@ -1708,6 +1708,12 @@ xpc::GetCurrentCompartmentName(JSContext* cx, nsCString& name)
GetCompartmentName(compartment, name, &anonymizeID, false);
}
JSRuntime*
xpc::GetJSRuntime()
{
return XPCJSRuntime::Get()->Runtime();
}
static int64_t
JSMainRuntimeGCHeapDistinguishedAmount()
{

View File

@ -22,7 +22,6 @@
#include "nsArrayEnumerator.h"
#include "nsCOMArray.h"
#include "nsDirectoryServiceUtils.h"
#include "nsIJSRuntimeService.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsJSPrincipals.h"
@ -1391,15 +1390,9 @@ XRE_XPCShellMain(int argc, char** argv, char** envp)
return 1;
}
nsCOMPtr<nsIJSRuntimeService> rtsvc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
// get the JSRuntime from the runtime svc
if (!rtsvc) {
printf("failed to get nsJSRuntimeService!\n");
return 1;
}
if (NS_FAILED(rtsvc->GetRuntime(&rt)) || !rt) {
printf("failed to get JSRuntime from nsJSRuntimeService!\n");
rt = xpc::GetJSRuntime();
if (!rt) {
printf("failed to get JSRuntime from XPConnect!\n");
return 1;
}

View File

@ -535,6 +535,9 @@ DispatchScriptErrorEvent(nsPIDOMWindow* win, JSRuntime* rt, xpc::ErrorReport* xp
extern void
GetCurrentCompartmentName(JSContext*, nsCString& name);
JSRuntime*
GetJSRuntime();
} // namespace xpc
namespace mozilla {

View File

@ -10,7 +10,6 @@
#include "jsapi.h"
#include "xpcpublic.h"
#include "nsIJSRuntimeService.h"
#include "nsIAddonInterposition.h"
#include "nsIAppStartup.h"
#include "nsIDirectoryEnumerator.h"
@ -893,14 +892,9 @@ nsXREDirProvider::DoShutdown()
// Phase 2c: Now that things are torn down, force JS GC so that things which depend on
// resources which are about to go away in "profile-before-change" are destroyed first.
nsCOMPtr<nsIJSRuntimeService> rtsvc
(do_GetService("@mozilla.org/js/xpc/RuntimeService;1"));
if (rtsvc)
{
JSRuntime *rt = nullptr;
rtsvc->GetRuntime(&rt);
if (rt)
::JS_GC(rt);
JSRuntime *rt = xpc::GetJSRuntime();
if (rt) {
JS_GC(rt);
}
// Phase 3: Notify observers of a profile change