зеркало из https://github.com/mozilla/gecko-dev.git
Bug 767938 part 5. Stop using the JSContext stack to get the current JSContext. r=bholley
This commit is contained in:
Родитель
53a1c93f93
Коммит
edb18fcfaf
|
@ -266,6 +266,13 @@ GetWebIDLCallerPrincipal()
|
|||
return aes->mWebIDLCallerPrincipal;
|
||||
}
|
||||
|
||||
bool
|
||||
IsJSAPIActive()
|
||||
{
|
||||
ScriptSettingsStackEntry* topEntry = ScriptSettingsStack::Top();
|
||||
return topEntry && !topEntry->NoJSAPI();
|
||||
}
|
||||
|
||||
AutoJSAPI::AutoJSAPI()
|
||||
: ScriptSettingsStackEntry(nullptr, eJSAPI)
|
||||
, mCx(nullptr)
|
||||
|
@ -796,13 +803,13 @@ AutoJSContext::AutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
|
|||
{
|
||||
JS::AutoSuppressGCAnalysis nogc;
|
||||
MOZ_ASSERT(!mCx, "mCx should not be initialized!");
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
|
||||
nsXPConnect *xpc = nsXPConnect::XPConnect();
|
||||
mCx = xpc->GetCurrentJSContext();
|
||||
|
||||
if (!mCx) {
|
||||
if (IsJSAPIActive()) {
|
||||
mCx = nsContentUtils::GetSafeJSContext();
|
||||
} else {
|
||||
mJSAPI.Init();
|
||||
mCx = mJSAPI.cx();
|
||||
}
|
||||
|
|
|
@ -150,6 +150,11 @@ inline JSObject& IncumbentJSGlobal()
|
|||
return *GetIncumbentGlobal()->GetGlobalJSObject();
|
||||
}
|
||||
|
||||
// Returns whether JSAPI is active right now. If it is not, working with a
|
||||
// JSContext you grab from somewhere random is not OK and you should be doing
|
||||
// AutoJSAPI or AutoEntryScript to get yourself a properly set up JSContext.
|
||||
bool IsJSAPIActive();
|
||||
|
||||
class ScriptSettingsStack;
|
||||
class ScriptSettingsStackEntry {
|
||||
friend class ScriptSettingsStack;
|
||||
|
|
|
@ -5469,7 +5469,10 @@ nsContentUtils::GetCurrentJSContext()
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(IsInitialized());
|
||||
return sXPConnect->GetCurrentJSContext();
|
||||
if (!IsJSAPIActive()) {
|
||||
return nullptr;
|
||||
}
|
||||
return GetSafeJSContext();
|
||||
}
|
||||
|
||||
/* static */
|
||||
|
|
Загрузка…
Ссылка в новой задаче