зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1359245 - Eliminate some XPCJSContext::Get() usage (r=mccr8)
XPCJSContext::Get() now does a TLS lookup, which is a little more expensive than looking up a global variable. This patch removes as many of the TLS lookups as possible. MozReview-Commit-ID: GsqzJn55Lya
This commit is contained in:
Родитель
3e774f9f8a
Коммит
133ed14a85
|
@ -1633,7 +1633,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
|
||||||
JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
|
JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
|
||||||
JS::MutableHandle<JS::PropertyDescriptor> desc)
|
JS::MutableHandle<JS::PropertyDescriptor> desc)
|
||||||
{
|
{
|
||||||
if (id == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)) {
|
if (id == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)) {
|
||||||
return LookupComponentsShim(cx, obj, aWin->AsInner(), desc);
|
return LookupComponentsShim(cx, obj, aWin->AsInner(), desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1641,7 +1641,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
|
||||||
// Note: We use |obj| rather than |aWin| to get the principal here, because
|
// Note: We use |obj| rather than |aWin| to get the principal here, because
|
||||||
// this is called during Window setup when the Document isn't necessarily
|
// this is called during Window setup when the Document isn't necessarily
|
||||||
// hooked up yet.
|
// hooked up yet.
|
||||||
if (id == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS) &&
|
if (id == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS) &&
|
||||||
!xpc::IsXrayWrapper(obj) &&
|
!xpc::IsXrayWrapper(obj) &&
|
||||||
!nsContentUtils::IsSystemPrincipal(nsContentUtils::ObjectPrincipal(obj)))
|
!nsContentUtils::IsSystemPrincipal(nsContentUtils::ObjectPrincipal(obj)))
|
||||||
{
|
{
|
||||||
|
|
|
@ -5058,11 +5058,11 @@ nsGlobalWindow::MayResolve(jsid aId)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aId == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)) {
|
if (aId == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_COMPONENTS)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aId == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS)) {
|
if (aId == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_CONTROLLERS)) {
|
||||||
// We only resolve .controllers in release builds and on non-chrome windows,
|
// We only resolve .controllers in release builds and on non-chrome windows,
|
||||||
// but let's not worry about any of that stuff.
|
// but let's not worry about any of that stuff.
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -487,7 +487,7 @@ sandbox_addProperty(JSContext* cx, HandleObject obj, HandleId id, HandleValue v)
|
||||||
// Whenever JS_EnumerateStandardClasses is called, it defines the
|
// Whenever JS_EnumerateStandardClasses is called, it defines the
|
||||||
// "undefined" property, even if it's already defined. We don't want to do
|
// "undefined" property, even if it's already defined. We don't want to do
|
||||||
// anything in that case.
|
// anything in that case.
|
||||||
if (id == XPCJSContext::Get()->GetStringID(XPCJSContext::IDX_UNDEFINED))
|
if (id == XPCJSRuntime::Get()->GetStringID(XPCJSContext::IDX_UNDEFINED))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Avoid recursively triggering sandbox_addProperty in the
|
// Avoid recursively triggering sandbox_addProperty in the
|
||||||
|
|
|
@ -186,28 +186,28 @@ inline jsid
|
||||||
XPCCallContext::GetResolveName() const
|
XPCCallContext::GetResolveName() const
|
||||||
{
|
{
|
||||||
CHECK_STATE(HAVE_CONTEXT);
|
CHECK_STATE(HAVE_CONTEXT);
|
||||||
return XPCJSContext::Get()->GetResolveName();
|
return GetContext()->GetResolveName();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline jsid
|
inline jsid
|
||||||
XPCCallContext::SetResolveName(JS::HandleId name)
|
XPCCallContext::SetResolveName(JS::HandleId name)
|
||||||
{
|
{
|
||||||
CHECK_STATE(HAVE_CONTEXT);
|
CHECK_STATE(HAVE_CONTEXT);
|
||||||
return XPCJSContext::Get()->SetResolveName(name);
|
return GetContext()->SetResolveName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline XPCWrappedNative*
|
inline XPCWrappedNative*
|
||||||
XPCCallContext::GetResolvingWrapper() const
|
XPCCallContext::GetResolvingWrapper() const
|
||||||
{
|
{
|
||||||
CHECK_STATE(HAVE_OBJECT);
|
CHECK_STATE(HAVE_OBJECT);
|
||||||
return XPCJSContext::Get()->GetResolvingWrapper();
|
return GetContext()->GetResolvingWrapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline XPCWrappedNative*
|
inline XPCWrappedNative*
|
||||||
XPCCallContext::SetResolvingWrapper(XPCWrappedNative* w)
|
XPCCallContext::SetResolvingWrapper(XPCWrappedNative* w)
|
||||||
{
|
{
|
||||||
CHECK_STATE(HAVE_OBJECT);
|
CHECK_STATE(HAVE_OBJECT);
|
||||||
return XPCJSContext::Get()->SetResolvingWrapper(w);
|
return GetContext()->SetResolvingWrapper(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint16_t
|
inline uint16_t
|
||||||
|
@ -522,8 +522,8 @@ xpc_ForcePropertyResolve(JSContext* cx, JS::HandleObject obj, jsid idArg)
|
||||||
inline jsid
|
inline jsid
|
||||||
GetJSIDByIndex(JSContext* cx, unsigned index)
|
GetJSIDByIndex(JSContext* cx, unsigned index)
|
||||||
{
|
{
|
||||||
XPCJSContext* xpcx = nsXPConnect::XPConnect()->GetContext();
|
XPCJSRuntime* xpcrt = nsXPConnect::GetRuntimeInstance();
|
||||||
return xpcx->GetStringID(index);
|
return xpcrt->GetStringID(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
|
|
|
@ -844,7 +844,7 @@ XPCJSContext::BeforeProcessTask(bool aMightBlock)
|
||||||
|
|
||||||
// As we may be entering a nested event loop, we need to
|
// As we may be entering a nested event loop, we need to
|
||||||
// cancel any ongoing performance measurement.
|
// cancel any ongoing performance measurement.
|
||||||
js::ResetPerformanceMonitoring(Get()->Context());
|
js::ResetPerformanceMonitoring(Context());
|
||||||
|
|
||||||
CycleCollectedJSContext::BeforeProcessTask(aMightBlock);
|
CycleCollectedJSContext::BeforeProcessTask(aMightBlock);
|
||||||
}
|
}
|
||||||
|
@ -864,7 +864,7 @@ XPCJSContext::AfterProcessTask(uint32_t aNewRecursionDepth)
|
||||||
|
|
||||||
// Now that we are certain that the event is complete,
|
// Now that we are certain that the event is complete,
|
||||||
// we can flush any ongoing performance measurement.
|
// we can flush any ongoing performance measurement.
|
||||||
js::FlushPerformanceMonitoring(Get()->Context());
|
js::FlushPerformanceMonitoring(Context());
|
||||||
|
|
||||||
mozilla::jsipc::AfterProcessTask();
|
mozilla::jsipc::AfterProcessTask();
|
||||||
}
|
}
|
||||||
|
|
|
@ -781,7 +781,7 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx,
|
||||||
nsCOMPtr<nsIException> xpc_exception = aSyntheticException;
|
nsCOMPtr<nsIException> xpc_exception = aSyntheticException;
|
||||||
/* this one would be set by our error reporter */
|
/* this one would be set by our error reporter */
|
||||||
|
|
||||||
XPCJSContext* xpccx = XPCJSContext::Get();
|
XPCJSContext* xpccx = ccx.GetContext();
|
||||||
|
|
||||||
// Get this right away in case we do something below to cause JS code
|
// Get this right away in case we do something below to cause JS code
|
||||||
// to run.
|
// to run.
|
||||||
|
@ -988,7 +988,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
|
||||||
AutoValueVector args(cx);
|
AutoValueVector args(cx);
|
||||||
AutoScriptEvaluate scriptEval(cx);
|
AutoScriptEvaluate scriptEval(cx);
|
||||||
|
|
||||||
XPCJSContext* xpccx = XPCJSContext::Get();
|
XPCJSContext* xpccx = ccx.GetContext();
|
||||||
AutoSavePendingResult apr(xpccx);
|
AutoSavePendingResult apr(xpccx);
|
||||||
|
|
||||||
// XXX ASSUMES that retval is last arg. The xpidl compiler ensures this.
|
// XXX ASSUMES that retval is last arg. The xpidl compiler ensures this.
|
||||||
|
@ -1236,7 +1236,7 @@ pre_call_clean_up:
|
||||||
return CheckForException(ccx, aes, name, GetInterfaceName(),
|
return CheckForException(ccx, aes, name, GetInterfaceName(),
|
||||||
syntheticException);
|
syntheticException);
|
||||||
|
|
||||||
XPCJSContext::Get()->SetPendingException(nullptr); // XXX necessary?
|
xpccx->SetPendingException(nullptr); // XXX necessary?
|
||||||
|
|
||||||
// convert out args and result
|
// convert out args and result
|
||||||
// NOTE: this is the total number of native params, not just the args
|
// NOTE: this is the total number of native params, not just the args
|
||||||
|
|
|
@ -1287,7 +1287,7 @@ CallMethodHelper::Call()
|
||||||
{
|
{
|
||||||
mCallContext.SetRetVal(JS::UndefinedValue());
|
mCallContext.SetRetVal(JS::UndefinedValue());
|
||||||
|
|
||||||
XPCJSContext::Get()->SetPendingException(nullptr);
|
mCallContext.GetContext()->SetPendingException(nullptr);
|
||||||
|
|
||||||
if (mVTableIndex == 0) {
|
if (mVTableIndex == 0) {
|
||||||
return QueryInterfaceFastPath();
|
return QueryInterfaceFastPath();
|
||||||
|
|
|
@ -398,7 +398,7 @@ nsXPConnect::GetInfoForName(const char * name, nsIInterfaceInfo** info)
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsXPConnect::GarbageCollect(uint32_t reason)
|
nsXPConnect::GarbageCollect(uint32_t reason)
|
||||||
{
|
{
|
||||||
GetContext()->GarbageCollect(reason);
|
mRuntime->GarbageCollect(reason);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
#include "mozilla/CycleCollectedJSContext.h"
|
#include "mozilla/CycleCollectedJSContext.h"
|
||||||
#include "mozilla/CycleCollectedJSRuntime.h"
|
#include "mozilla/CycleCollectedJSRuntime.h"
|
||||||
|
#include "mozilla/DebugOnly.h"
|
||||||
#include "mozilla/GuardObjects.h"
|
#include "mozilla/GuardObjects.h"
|
||||||
#include "mozilla/Maybe.h"
|
#include "mozilla/Maybe.h"
|
||||||
#include "mozilla/MemoryReporting.h"
|
#include "mozilla/MemoryReporting.h"
|
||||||
|
@ -2494,24 +2495,25 @@ class MOZ_RAII AutoResolveName
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AutoResolveName(XPCCallContext& ccx, JS::HandleId name
|
AutoResolveName(XPCCallContext& ccx, JS::HandleId name
|
||||||
MOZ_GUARD_OBJECT_NOTIFIER_PARAM) :
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||||
mOld(ccx, XPCJSContext::Get()->SetResolveName(name))
|
: mContext(ccx.GetContext())
|
||||||
|
, mOld(ccx, mContext->SetResolveName(name))
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
,mCheck(ccx, name)
|
, mCheck(ccx, name)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
~AutoResolveName()
|
~AutoResolveName()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
mozilla::DebugOnly<jsid> old =
|
||||||
jsid old =
|
mContext->SetResolveName(mOld);
|
||||||
#endif
|
|
||||||
XPCJSContext::Get()->SetResolveName(mOld);
|
|
||||||
MOZ_ASSERT(old == mCheck, "Bad Nesting!");
|
MOZ_ASSERT(old == mCheck, "Bad Nesting!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
XPCJSContext* mContext;
|
||||||
JS::RootedId mOld;
|
JS::RootedId mOld;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
JS::RootedId mCheck;
|
JS::RootedId mCheck;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче