зеркало из https://github.com/mozilla/gecko-dev.git
bug 873622 - speed up nsXPConnect::GetXPConnect() and rename it since it never returns null r=bholley
This commit is contained in:
Родитель
afeb82e0c7
Коммит
efd48bef1e
|
@ -2422,11 +2422,7 @@ nsScriptSecurityManager::nsScriptSecurityManager(void)
|
|||
|
||||
nsresult nsScriptSecurityManager::Init()
|
||||
{
|
||||
nsXPConnect* xpconnect = nsXPConnect::GetXPConnect();
|
||||
if (!xpconnect)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_ADDREF(sXPConnect = xpconnect);
|
||||
NS_ADDREF(sXPConnect = nsXPConnect::XPConnect());
|
||||
|
||||
JSContext* cx = GetSafeJSContext();
|
||||
if (!cx) return NS_ERROR_FAILURE; // this can happen of xpt loading fails
|
||||
|
|
|
@ -361,10 +361,7 @@ nsContentUtils::Init()
|
|||
nsresult rv = NS_GetNameSpaceManager(&sNameSpaceManager);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsXPConnect* xpconnect = nsXPConnect::GetXPConnect();
|
||||
NS_ENSURE_TRUE(xpconnect, NS_ERROR_FAILURE);
|
||||
|
||||
sXPConnect = xpconnect;
|
||||
sXPConnect = nsXPConnect::XPConnect();
|
||||
|
||||
sSecurityManager = nsScriptSecurityManager::GetScriptSecurityManager();
|
||||
if(!sSecurityManager)
|
||||
|
|
|
@ -262,12 +262,7 @@ File(JSContext *cx, unsigned argc, Value *vp)
|
|||
return false;
|
||||
}
|
||||
|
||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||
if (!xpc) {
|
||||
XPCThrower::Throw(NS_ERROR_UNEXPECTED, cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
JSObject* glob = JS_GetGlobalForScopeChain(cx);
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
|
@ -302,12 +297,7 @@ Blob(JSContext *cx, unsigned argc, Value *vp)
|
|||
return false;
|
||||
}
|
||||
|
||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||
if (!xpc) {
|
||||
XPCThrower::Throw(NS_ERROR_UNEXPECTED, cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
JSObject* glob = JS_GetGlobalForScopeChain(cx);
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
|
|
|
@ -24,7 +24,7 @@ XPCCallContext::XPCCallContext(XPCContext::LangType callerLanguage,
|
|||
jsval *argv /* = nullptr */,
|
||||
jsval *rval /* = nullptr */)
|
||||
: mState(INIT_FAILED),
|
||||
mXPC(nsXPConnect::GetXPConnect()),
|
||||
mXPC(nsXPConnect::XPConnect()),
|
||||
mXPCContext(nullptr),
|
||||
mJSContext(cx),
|
||||
mContextPopRequired(false),
|
||||
|
@ -48,7 +48,7 @@ XPCCallContext::XPCCallContext(XPCContext::LangType callerLanguage,
|
|||
XPCWrappedNative* wrapper,
|
||||
XPCWrappedNativeTearOff* tearOff)
|
||||
: mState(INIT_FAILED),
|
||||
mXPC(nsXPConnect::GetXPConnect()),
|
||||
mXPC(nsXPConnect::XPConnect()),
|
||||
mXPCContext(nullptr),
|
||||
mJSContext(cx),
|
||||
mContextPopRequired(false),
|
||||
|
|
|
@ -65,10 +65,7 @@ JSValIsInterfaceOfType(JSContext *cx, HandleValue v, REFNSIID iid)
|
|||
if (v.isPrimitive())
|
||||
return false;
|
||||
|
||||
nsCOMPtr<nsIXPConnect> xpc = nsXPConnect::GetXPConnect();
|
||||
if (!xpc)
|
||||
return false;
|
||||
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
RootedObject obj(cx, &v.toObject());
|
||||
if (NS_SUCCEEDED(xpc->GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wn))) && wn &&
|
||||
NS_SUCCEEDED(wn->Native()->QueryInterface(iid, (void**)&iface)) && iface)
|
||||
|
@ -2808,9 +2805,8 @@ nsXPCComponents_Utils::ReportError(const JS::Value &errorArg, JSContext *cx)
|
|||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIStackFrame> frame;
|
||||
nsXPConnect *xpc = nsXPConnect::GetXPConnect();
|
||||
if (xpc)
|
||||
xpc->GetCurrentJSStack(getter_AddRefs(frame));
|
||||
nsXPConnect *xpc = nsXPConnect::XPConnect();
|
||||
xpc->GetCurrentJSStack(getter_AddRefs(frame));
|
||||
|
||||
nsXPIDLCString fileName;
|
||||
int32_t lineNo = 0;
|
||||
|
@ -3482,9 +3478,7 @@ GetPrincipalOrSOP(JSContext *cx, HandleObject from, nsISupports **out)
|
|||
MOZ_ASSERT(out);
|
||||
*out = NULL;
|
||||
|
||||
nsCOMPtr<nsIXPConnect> xpc = nsXPConnect::GetXPConnect();
|
||||
if (!xpc)
|
||||
return NS_ERROR_XPC_UNEXPECTED;
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
|
||||
xpc->GetWrappedNativeOfJSObject(cx, from,
|
||||
getter_AddRefs(wrapper));
|
||||
|
@ -3685,9 +3679,7 @@ AssembleSandboxMemoryReporterName(JSContext *cx, nsCString &sandboxName)
|
|||
if (sandboxName.IsEmpty())
|
||||
sandboxName = NS_LITERAL_CSTRING("[anonymous sandbox]");
|
||||
|
||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||
NS_ENSURE_TRUE(xpc, NS_ERROR_XPC_UNEXPECTED);
|
||||
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
// Get the xpconnect native call context.
|
||||
nsAXPCNativeCallContext *cc = nullptr;
|
||||
xpc->GetCurrentNativeCallContext(&cc);
|
||||
|
@ -4424,9 +4416,9 @@ nsXPCComponents_Utils::Dispatch(const jsval &runnableArg, const jsval &scope,
|
|||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsCOMPtr<nsIRunnable> run;
|
||||
nsresult rv = nsXPConnect::GetXPConnect()->WrapJS(cx, &runnable.toObject(),
|
||||
NS_GET_IID(nsIRunnable),
|
||||
getter_AddRefs(run));
|
||||
nsresult rv = nsXPConnect::XPConnect()->WrapJS(cx, &runnable.toObject(),
|
||||
NS_GET_IID(nsIRunnable),
|
||||
getter_AddRefs(run));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
MOZ_ASSERT(run);
|
||||
|
||||
|
@ -4769,9 +4761,7 @@ NS_IMETHODIMP
|
|||
nsXPCComponents::GetStack(nsIStackFrame * *aStack)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||
if (!xpc)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
rv = xpc->GetCurrentJSStack(aStack);
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -297,9 +297,7 @@ nsXPCException::Initialize(const char *aMessage, nsresult aResult, const char *a
|
|||
return rc;
|
||||
} else {
|
||||
nsresult rv;
|
||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||
if (!xpc)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
rv = xpc->GetCurrentJSStack(&mLocation);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
@ -400,11 +398,7 @@ nsXPCException::NewException(const char *aMessage,
|
|||
location = aLocation;
|
||||
NS_ADDREF(location);
|
||||
} else {
|
||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||
if (!xpc) {
|
||||
NS_RELEASE(e);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
rv = xpc->GetCurrentJSStack(&location);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(e);
|
||||
|
|
|
@ -147,10 +147,7 @@ XPCJSContextStack::GetSafeJSContext()
|
|||
if (NS_FAILED(rv))
|
||||
return NULL;
|
||||
|
||||
nsRefPtr<nsXPConnect> xpc = nsXPConnect::GetXPConnect();
|
||||
if (!xpc)
|
||||
return NULL;
|
||||
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
XPCJSRuntime* xpcrt = xpc->GetRuntime();
|
||||
if (!xpcrt)
|
||||
return NULL;
|
||||
|
|
|
@ -715,10 +715,7 @@ static void
|
|||
GetWrapperObject(MutableHandleObject obj)
|
||||
{
|
||||
obj.set(NULL);
|
||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||
if (!xpc)
|
||||
return;
|
||||
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
nsAXPCNativeCallContext *ccxp = NULL;
|
||||
xpc->GetCurrentNativeCallContext(&ccxp);
|
||||
if (!ccxp)
|
||||
|
@ -770,7 +767,7 @@ nsJSCID::CreateInstance(const JS::Value& iidval, JSContext* cx,
|
|||
if (NS_FAILED(rv) || !inst)
|
||||
return NS_ERROR_XPC_CI_RETURNED_FAILURE;
|
||||
|
||||
rv = nsXPConnect::GetXPConnect()->WrapNativeToJSVal(cx, obj, inst, nullptr, iid, true, retval, nullptr);
|
||||
rv = nsXPConnect::XPConnect()->WrapNativeToJSVal(cx, obj, inst, nullptr, iid, true, retval, nullptr);
|
||||
if (NS_FAILED(rv) || JSVAL_IS_PRIMITIVE(*retval))
|
||||
return NS_ERROR_XPC_CANT_CREATE_WN;
|
||||
return NS_OK;
|
||||
|
@ -819,7 +816,7 @@ nsJSCID::GetService(const JS::Value& iidval, JSContext* cx,
|
|||
|
||||
RootedObject instJSObj(cx);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = nsXPConnect::GetXPConnect()->WrapNative(cx, obj, srvc, *iid, getter_AddRefs(holder));
|
||||
rv = nsXPConnect::XPConnect()->WrapNative(cx, obj, srvc, *iid, getter_AddRefs(holder));
|
||||
if (NS_FAILED(rv) || !holder ||
|
||||
// Assign, not compare
|
||||
!(instJSObj = holder->GetJSObject()))
|
||||
|
@ -896,7 +893,7 @@ xpc_NewIDObject(JSContext *cx, HandleObject jsobj, const nsID& aID)
|
|||
nsCOMPtr<nsIJSID> iid =
|
||||
dont_AddRef(static_cast<nsIJSID*>(nsJSID::NewID(aID)));
|
||||
if (iid) {
|
||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
if (xpc) {
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
nsresult rv = xpc->WrapNative(cx, jsobj,
|
||||
|
|
|
@ -608,9 +608,8 @@ XPCJSRuntime::UnmarkSkippableJSHolders()
|
|||
void
|
||||
xpc_UnmarkSkippableJSHolders()
|
||||
{
|
||||
if (nsXPConnect::GetXPConnect() &&
|
||||
nsXPConnect::GetXPConnect()->GetRuntime()) {
|
||||
nsXPConnect::GetXPConnect()->GetRuntime()->UnmarkSkippableJSHolders();
|
||||
if (nsXPConnect::XPConnect()->GetRuntime()) {
|
||||
nsXPConnect::XPConnect()->GetRuntime()->UnmarkSkippableJSHolders();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2259,7 +2258,7 @@ class XPCJSRuntimeStats : public JS::RuntimeStats
|
|||
|
||||
virtual void initExtraZoneStats(JS::Zone *zone, JS::ZoneStats *zStats) MOZ_OVERRIDE {
|
||||
// Get the compartment's global.
|
||||
nsXPConnect *xpc = nsXPConnect::GetXPConnect();
|
||||
nsXPConnect *xpc = nsXPConnect::XPConnect();
|
||||
AutoSafeJSContext cx;
|
||||
JSCompartment *comp = js::GetAnyCompartmentInZone(zone);
|
||||
xpc::ZoneStatsExtras *extras = new xpc::ZoneStatsExtras;
|
||||
|
@ -2292,7 +2291,7 @@ class XPCJSRuntimeStats : public JS::RuntimeStats
|
|||
GetCompartmentName(c, cName, true);
|
||||
|
||||
// Get the compartment's global.
|
||||
nsXPConnect *xpc = nsXPConnect::GetXPConnect();
|
||||
nsXPConnect *xpc = nsXPConnect::XPConnect();
|
||||
AutoSafeJSContext cx;
|
||||
bool needZone = true;
|
||||
RootedObject global(cx, JS_GetGlobalForCompartmentOrNull(cx, c));
|
||||
|
@ -3004,8 +3003,8 @@ XPCRootSetElem::AddToRootSet(XPCLock *lock, XPCRootSetElem **listHead)
|
|||
void
|
||||
XPCRootSetElem::RemoveFromRootSet(XPCLock *lock)
|
||||
{
|
||||
if (nsXPConnect *xpc = nsXPConnect::GetXPConnect())
|
||||
JS::PokeGC(xpc->GetRuntime()->GetJSRuntime());
|
||||
nsXPConnect *xpc = nsXPConnect::XPConnect();
|
||||
JS::PokeGC(xpc->GetRuntime()->GetJSRuntime());
|
||||
|
||||
NS_ASSERTION(mSelfp, "Must be linked");
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ nsresult xpcJSWeakReference::Init(JSContext* cx, const JS::Value& object)
|
|||
|
||||
// See if the object is a wrapped native that supports weak references.
|
||||
nsISupports* supports =
|
||||
nsXPConnect::GetXPConnect()->GetNativeOfWrapper(cx, obj);
|
||||
nsXPConnect::XPConnect()->GetNativeOfWrapper(cx, obj);
|
||||
nsCOMPtr<nsISupportsWeakReference> supportsWeakRef =
|
||||
do_QueryInterface(supports);
|
||||
if (supportsWeakRef) {
|
||||
|
|
|
@ -65,7 +65,7 @@ LookupInterfaceOrAncestor(uint32_t tableSize, const xpc_qsHashEntry *table,
|
|||
* supports, including ancestors.
|
||||
*/
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
if (NS_FAILED(nsXPConnect::GetXPConnect()->GetInfoForIID(&iid, getter_AddRefs(info))))
|
||||
if (NS_FAILED(nsXPConnect::XPConnect()->GetInfoForIID(&iid, getter_AddRefs(info))))
|
||||
return nullptr;
|
||||
|
||||
const nsIID *piid;
|
||||
|
|
|
@ -241,7 +241,7 @@ XPCThrower::ThrowExceptionObject(JSContext* cx, nsIException* e)
|
|||
return false;
|
||||
JS_SetPendingException(cx, thrown);
|
||||
success = true;
|
||||
} else if ((xpc = nsXPConnect::GetXPConnect())) {
|
||||
} else if ((xpc = nsXPConnect::XPConnect())) {
|
||||
JS::RootedObject glob(cx, JS_GetGlobalForScopeChain(cx));
|
||||
if (!glob)
|
||||
return false;
|
||||
|
|
|
@ -350,12 +350,11 @@ JSBool XPCVariant::InitializeData(JSContext* cx)
|
|||
|
||||
// XXX This could be smarter and pick some more interesting iface.
|
||||
|
||||
nsXPConnect* xpc;
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
nsCOMPtr<nsISupports> wrapper;
|
||||
const nsIID& iid = NS_GET_IID(nsISupports);
|
||||
|
||||
return nullptr != (xpc = nsXPConnect::GetXPConnect()) &&
|
||||
NS_SUCCEEDED(xpc->WrapJS(cx, jsobj,
|
||||
return NS_SUCCEEDED(xpc->WrapJS(cx, jsobj,
|
||||
iid, getter_AddRefs(wrapper))) &&
|
||||
NS_SUCCEEDED(nsVariant::SetFromInterface(&mData, iid, wrapper));
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ nsXPCWrappedJSClass::GetNewOrUsed(JSContext* cx, REFNSIID aIID,
|
|||
|
||||
if (!clazz) {
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
nsXPConnect::GetXPConnect()->GetInfoForIID(&aIID, getter_AddRefs(info));
|
||||
nsXPConnect::XPConnect()->GetInfoForIID(&aIID, getter_AddRefs(info));
|
||||
if (info) {
|
||||
bool canScript, isBuiltin;
|
||||
if (NS_SUCCEEDED(info->IsScriptable(&canScript)) && canScript &&
|
||||
|
@ -240,7 +240,7 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(JSContext* cx,
|
|||
// We so often ask for nsISupports that we can short-circuit the test...
|
||||
if (!aIID.Equals(NS_GET_IID(nsISupports))) {
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
nsXPConnect::GetXPConnect()->GetInfoForIID(&aIID, getter_AddRefs(info));
|
||||
nsXPConnect::XPConnect()->GetInfoForIID(&aIID, getter_AddRefs(info));
|
||||
if (!info)
|
||||
return nullptr;
|
||||
bool canScript, isBuiltin;
|
||||
|
@ -276,7 +276,7 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(JSContext* cx,
|
|||
// C++ QI failure. See if that is the case.
|
||||
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
|
||||
|
||||
nsXPConnect::GetXPConnect()->
|
||||
nsXPConnect::XPConnect()->
|
||||
GetWrappedNativeOfJSObject(cx,
|
||||
&jsexception.toObject(),
|
||||
getter_AddRefs(wrapper));
|
||||
|
@ -684,7 +684,7 @@ nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self,
|
|||
|
||||
*aInstancePtr = nullptr;
|
||||
|
||||
nsXPConnect *xpc = nsXPConnect::GetXPConnect();
|
||||
nsXPConnect *xpc = nsXPConnect::XPConnect();
|
||||
nsCOMPtr<nsIScriptSecurityManager> secMan =
|
||||
do_QueryInterface(xpc->GetDefaultSecurityManager());
|
||||
if (!secMan)
|
||||
|
|
|
@ -117,13 +117,7 @@ nsCxPusher::Push(JSContext *cx)
|
|||
void
|
||||
nsCxPusher::DoPush(JSContext* cx)
|
||||
{
|
||||
nsIXPConnect *xpc = nsXPConnect::GetXPConnect();
|
||||
if (!xpc) {
|
||||
// If someone tries to push a cx when we don't have the relevant state,
|
||||
// it's probably safest to just crash.
|
||||
MOZ_CRASH();
|
||||
}
|
||||
|
||||
nsXPConnect *xpc = nsXPConnect::XPConnect();
|
||||
// NB: The GetDynamicScriptContext is historical and might not be sane.
|
||||
if (cx && nsJSUtils::GetDynamicScriptContext(cx) &&
|
||||
xpc::IsJSContextOnStack(cx))
|
||||
|
@ -171,7 +165,6 @@ nsCxPusher::Pop()
|
|||
|
||||
return;
|
||||
}
|
||||
MOZ_ASSERT(nsXPConnect::GetXPConnect());
|
||||
|
||||
// Leave the request before popping.
|
||||
mAutoRequest.destroyIfConstructed();
|
||||
|
@ -184,7 +177,7 @@ nsCxPusher::Pop()
|
|||
MOZ_ASSERT_IF(mPushedContext, mCompartmentDepthOnEntry ==
|
||||
js::GetEnterCompartmentDepth(mPushedContext));
|
||||
DebugOnly<JSContext*> stackTop;
|
||||
MOZ_ASSERT(mPushedContext == nsXPConnect::GetXPConnect()->GetCurrentJSContext());
|
||||
MOZ_ASSERT(mPushedContext == nsXPConnect::XPConnect()->GetCurrentJSContext());
|
||||
xpc::PopJSContext();
|
||||
|
||||
if (!mScriptIsRunning && mScx) {
|
||||
|
@ -220,7 +213,7 @@ AutoJSContext::Init(bool aSafe MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
|
|||
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
|
||||
nsIXPConnect *xpc = nsXPConnect::GetXPConnect();
|
||||
nsXPConnect *xpc = nsXPConnect::XPConnect();
|
||||
if (!aSafe) {
|
||||
mCx = xpc->GetCurrentJSContext();
|
||||
}
|
||||
|
@ -243,7 +236,7 @@ AutoSafeJSContext::AutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMP
|
|||
|
||||
AutoPushJSContext::AutoPushJSContext(JSContext *aCx) : mCx(aCx)
|
||||
{
|
||||
if (mCx && mCx != nsXPConnect::GetXPConnect()->GetCurrentJSContext()) {
|
||||
if (mCx && mCx != nsXPConnect::XPConnect()->GetCurrentJSContext()) {
|
||||
mPusher.Push(mCx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,48 +137,29 @@ nsXPConnect::~nsXPConnect()
|
|||
}
|
||||
|
||||
// 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 (!MOZ_LIKELY(NS_IsMainThread() || NS_IsCycleCollectorThread()))
|
||||
MOZ_CRASH();
|
||||
|
||||
if (!gSelf) {
|
||||
if (gOnceAliveNowDead)
|
||||
return nullptr;
|
||||
gSelf = new nsXPConnect();
|
||||
if (!gSelf)
|
||||
return nullptr;
|
||||
|
||||
if (!gSelf->mRuntime) {
|
||||
NS_RUNTIMEABORT("Couldn't create XPCJSRuntime.");
|
||||
}
|
||||
|
||||
// Initial extra ref to keep the singleton alive
|
||||
// balanced by explicit call to ReleaseXPConnectSingleton()
|
||||
NS_ADDREF(gSelf);
|
||||
|
||||
// Set XPConnect as the main thread observer.
|
||||
//
|
||||
// The cycle collector sometimes calls GetXPConnect, but it should never
|
||||
// be the one that initializes gSelf.
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
if (NS_FAILED(nsThread::SetMainThreadObserver(gSelf))) {
|
||||
NS_RELEASE(gSelf);
|
||||
// Fall through to returning null
|
||||
}
|
||||
void
|
||||
nsXPConnect::InitStatics()
|
||||
{
|
||||
gSelf = new nsXPConnect();
|
||||
gOnceAliveNowDead = false;
|
||||
if (!gSelf->mRuntime) {
|
||||
NS_RUNTIMEABORT("Couldn't create XPCJSRuntime.");
|
||||
}
|
||||
|
||||
// Initial extra ref to keep the singleton alive
|
||||
// balanced by explicit call to ReleaseXPConnectSingleton()
|
||||
NS_ADDREF(gSelf);
|
||||
|
||||
// Set XPConnect as the main thread observer.
|
||||
if (NS_FAILED(nsThread::SetMainThreadObserver(gSelf))) {
|
||||
MOZ_CRASH();
|
||||
}
|
||||
return gSelf;
|
||||
}
|
||||
|
||||
// static
|
||||
nsXPConnect*
|
||||
nsXPConnect::GetSingleton()
|
||||
{
|
||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
NS_IF_ADDREF(xpc);
|
||||
return xpc;
|
||||
}
|
||||
|
@ -230,8 +211,7 @@ nsXPConnect::ReleaseXPConnectSingleton()
|
|||
XPCJSRuntime*
|
||||
nsXPConnect::GetRuntimeInstance()
|
||||
{
|
||||
nsXPConnect* xpc = GetXPConnect();
|
||||
NS_ASSERTION(xpc, "Must not be called if XPC failed to initialize");
|
||||
nsXPConnect* xpc = XPConnect();
|
||||
return xpc->GetRuntime();
|
||||
}
|
||||
|
||||
|
@ -2051,7 +2031,7 @@ NS_EXPORT_(void)
|
|||
xpc_ActivateDebugMode()
|
||||
{
|
||||
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
|
||||
nsXPConnect::GetXPConnect()->SetDebugModeWhenPossible(true, true);
|
||||
nsXPConnect::XPConnect()->SetDebugModeWhenPossible(true, true);
|
||||
nsXPConnect::CheckForDebugMode(rt->GetJSRuntime());
|
||||
}
|
||||
|
||||
|
@ -2076,7 +2056,7 @@ bool
|
|||
PushJSContext(JSContext *aCx)
|
||||
{
|
||||
// JSD mumbo jumbo.
|
||||
nsXPConnect *xpc = nsXPConnect::GetXPConnect();
|
||||
nsXPConnect *xpc = nsXPConnect::XPConnect();
|
||||
JSRuntime *rt = XPCJSRuntime::Get()->GetJSRuntime();
|
||||
if (xpc::gDebugMode != xpc::gDesiredDebugMode) {
|
||||
if (!xpc::gDesiredDebugMode) {
|
||||
|
@ -2251,11 +2231,7 @@ void
|
|||
DumpJSHeap(FILE* file)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Must dump GC heap on main thread.");
|
||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||
if (!xpc) {
|
||||
NS_ERROR("Failed to get nsXPConnect instance!");
|
||||
return;
|
||||
}
|
||||
nsXPConnect* xpc = nsXPConnect::XPConnect();
|
||||
js::DumpHeapComplete(xpc->GetRuntime()->GetJSRuntime(), file);
|
||||
}
|
||||
|
||||
|
|
|
@ -109,6 +109,7 @@
|
|||
#include "nsAutoPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsCycleCollectionJSRuntime.h"
|
||||
#include "nsCycleCollectorUtils.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
@ -476,8 +477,18 @@ public:
|
|||
// non-interface implementation
|
||||
public:
|
||||
// These get non-addref'd pointers
|
||||
static nsXPConnect* GetXPConnect();
|
||||
static nsXPConnect* FastGetXPConnect() { return gSelf ? gSelf : GetXPConnect(); }
|
||||
static nsXPConnect* XPConnect()
|
||||
{
|
||||
// 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 (!MOZ_LIKELY(NS_IsMainThread() || NS_IsCycleCollectorThread()))
|
||||
MOZ_CRASH();
|
||||
|
||||
return gSelf;
|
||||
}
|
||||
|
||||
static nsXPConnect* FastGetXPConnect() { return gSelf ? gSelf : XPConnect(); }
|
||||
static XPCJSRuntime* GetRuntimeInstance();
|
||||
XPCJSRuntime* GetRuntime() {return mRuntime;}
|
||||
|
||||
|
@ -506,7 +517,7 @@ public:
|
|||
static nsXPConnect* GetSingleton();
|
||||
|
||||
// Called by module code in dll startup
|
||||
static void InitStatics() { gSelf = nullptr; gOnceAliveNowDead = false; }
|
||||
static void InitStatics();
|
||||
// Called by module code on dll shutdown.
|
||||
static void ReleaseXPConnectSingleton();
|
||||
|
||||
|
@ -644,7 +655,7 @@ class XPCJSRuntime
|
|||
{
|
||||
public:
|
||||
static XPCJSRuntime* newXPCJSRuntime(nsXPConnect* aXPConnect);
|
||||
static XPCJSRuntime* Get() { return nsXPConnect::GetXPConnect()->GetRuntime(); }
|
||||
static XPCJSRuntime* Get() { return nsXPConnect::XPConnect()->GetRuntime(); }
|
||||
|
||||
JSRuntime* GetJSRuntime() const {return mJSRuntime;}
|
||||
nsXPConnect* GetXPConnect() const {return mXPConnect;}
|
||||
|
|
|
@ -1947,7 +1947,7 @@ do_QueryInterfaceNative(JSContext* cx, HandleObject wrapper)
|
|||
nativeSupports = wn->Native();
|
||||
}
|
||||
} else {
|
||||
nsIXPConnect *xpc = nsXPConnect::GetXPConnect();
|
||||
nsIXPConnect *xpc = nsXPConnect::XPConnect();
|
||||
nativeSupports = xpc->GetNativeOfWrapper(cx, wrapper);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче