зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1282150 part 2. Get rid of GetDefaultJSContextForThread. r=bholley
This commit is contained in:
Родитель
6542e6c3f0
Коммит
e990418707
|
@ -334,7 +334,7 @@ AutoJSAPI::InitInternal(nsIGlobalObject* aGlobalObject, JSObject* aGlobal,
|
|||
JSContext* aCx, bool aIsMainThread)
|
||||
{
|
||||
MOZ_ASSERT(aCx);
|
||||
MOZ_ASSERT(aCx == nsContentUtils::GetDefaultJSContextForThread());
|
||||
MOZ_ASSERT(aCx == danger::GetJSContext());
|
||||
MOZ_ASSERT(aIsMainThread == NS_IsMainThread());
|
||||
MOZ_ASSERT(bool(aGlobalObject) == bool(aGlobal));
|
||||
MOZ_ASSERT_IF(aGlobalObject, aGlobalObject->GetGlobalJSObject() == aGlobal);
|
||||
|
@ -437,8 +437,7 @@ AutoJSAPI::AutoJSAPI(nsIGlobalObject* aGlobalObject,
|
|||
MOZ_ASSERT(aIsMainThread == NS_IsMainThread());
|
||||
|
||||
InitInternal(aGlobalObject, aGlobalObject->GetGlobalJSObject(),
|
||||
nsContentUtils::GetDefaultJSContextForThread(),
|
||||
aIsMainThread);
|
||||
danger::GetJSContext(), aIsMainThread);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -447,8 +446,7 @@ AutoJSAPI::Init()
|
|||
MOZ_ASSERT(!mCx, "An AutoJSAPI should only be initialised once");
|
||||
|
||||
InitInternal(/* aGlobalObject */ nullptr, /* aGlobal */ nullptr,
|
||||
nsContentUtils::GetDefaultJSContextForThread(),
|
||||
NS_IsMainThread());
|
||||
danger::GetJSContext(), NS_IsMainThread());
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -473,7 +471,7 @@ AutoJSAPI::Init(nsIGlobalObject* aGlobalObject, JSContext* aCx)
|
|||
bool
|
||||
AutoJSAPI::Init(nsIGlobalObject* aGlobalObject)
|
||||
{
|
||||
return Init(aGlobalObject, nsContentUtils::GetDefaultJSContextForThread());
|
||||
return Init(aGlobalObject, danger::GetJSContext());
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -5558,18 +5558,6 @@ nsContentUtils::GetSafeJSContext()
|
|||
return sXPConnect->GetSafeJSContext();
|
||||
}
|
||||
|
||||
/* static */
|
||||
JSContext *
|
||||
nsContentUtils::GetDefaultJSContextForThread()
|
||||
{
|
||||
MOZ_ASSERT(IsInitialized());
|
||||
if (MOZ_LIKELY(NS_IsMainThread())) {
|
||||
return GetSafeJSContext();
|
||||
} else {
|
||||
return workers::GetCurrentThreadJSContext();
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
JSContext *
|
||||
nsContentUtils::GetCurrentJSContextForThread()
|
||||
|
|
|
@ -1724,9 +1724,10 @@ public:
|
|||
static JSContext *GetCurrentJSContext();
|
||||
static JSContext *GetSafeJSContext();
|
||||
static JSContext *GetCurrentJSContextForThread();
|
||||
static JSContext *GetDefaultJSContextForThread();
|
||||
inline static JSContext *RootingCx() { return GetSafeJSContext(); }
|
||||
inline static JSContext *RootingCxForThread() { return GetDefaultJSContextForThread(); }
|
||||
inline static JSContext *RootingCxForThread() {
|
||||
return mozilla::dom::danger::GetJSContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Case insensitive comparison between two strings. However it only ignores
|
||||
|
|
|
@ -359,7 +359,7 @@ void
|
|||
ErrorResult::ClearUnionData()
|
||||
{
|
||||
if (IsJSException()) {
|
||||
JSContext* cx = nsContentUtils::GetDefaultJSContextForThread();
|
||||
JSContext* cx = nsContentUtils::RootingCxForThread();
|
||||
MOZ_ASSERT(cx);
|
||||
mJSException.setUndefined();
|
||||
js::RemoveRawValueRoot(cx, &mJSException);
|
||||
|
@ -398,7 +398,7 @@ ErrorResult::operator=(ErrorResult&& aRHS)
|
|||
mMessage = aRHS.mMessage;
|
||||
aRHS.mMessage = nullptr;
|
||||
} else if (aRHS.IsJSException()) {
|
||||
JSContext* cx = nsContentUtils::GetDefaultJSContextForThread();
|
||||
JSContext* cx = nsContentUtils::RootingCxForThread();
|
||||
MOZ_ASSERT(cx);
|
||||
mJSException.setUndefined();
|
||||
if (!js::AddRawValueRoot(cx, &mJSException, "ErrorResult::mJSException")) {
|
||||
|
|
|
@ -9,13 +9,14 @@
|
|||
#include "jsapi.h"
|
||||
#include "js/Class.h"
|
||||
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsJSPrincipals.h"
|
||||
#include "nsNullPrincipal.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
#include "xpcprivate.h"
|
||||
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
|
@ -90,8 +91,9 @@ const js::Class SimpleGlobalClass = {
|
|||
JSObject*
|
||||
SimpleGlobalObject::Create(GlobalType globalType, JS::Handle<JS::Value> proto)
|
||||
{
|
||||
JSContext* cx = nsContentUtils::GetDefaultJSContextForThread();
|
||||
JSAutoRequest ar(cx);
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init();
|
||||
JSContext* cx = jsapi.cx();
|
||||
|
||||
JS::CompartmentOptions options;
|
||||
options.creationOptions().setInvisibleToDebugger(true);
|
||||
|
@ -111,7 +113,7 @@ SimpleGlobalObject::Create(GlobalType globalType, JS::Handle<JS::Value> proto)
|
|||
}
|
||||
|
||||
if (!global) {
|
||||
JS_ClearPendingException(cx);
|
||||
jsapi.ClearException();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -130,12 +132,12 @@ SimpleGlobalObject::Create(GlobalType globalType, JS::Handle<JS::Value> proto)
|
|||
if (proto.isObjectOrNull()) {
|
||||
JS::Rooted<JSObject*> protoObj(cx, proto.toObjectOrNull());
|
||||
if (!JS_WrapObject(cx, &protoObj)) {
|
||||
JS_ClearPendingException(cx);
|
||||
jsapi.ClearException();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!JS_SplicePrototype(cx, global, protoObj)) {
|
||||
JS_ClearPendingException(cx);
|
||||
jsapi.ClearException();
|
||||
return nullptr;
|
||||
}
|
||||
} else if (!proto.isUndefined()) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче