Bug 1541513 part 3. Stop using AutoJSContext in NativeInterface2JSObject. r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D26002

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-04-04 02:07:53 +00:00
Родитель 953426c78f
Коммит 6f668b8c00
5 изменённых файлов: 22 добавлений и 22 удалений

Просмотреть файл

@ -1046,7 +1046,7 @@ static bool NativeInterface2JSObjectAndThrowIfFailed(
MOZ_ASSERT(NS_IsMainThread());
if (!XPCConvert::NativeInterface2JSObject(aRetval, aHelper, aIID,
if (!XPCConvert::NativeInterface2JSObject(aCx, aRetval, aHelper, aIID,
aAllowNativeWrapper, &rv)) {
// I can't tell if NativeInterface2JSObject throws JS exceptions
// or not. This is a sloppy stab at the right semantics; the

Просмотреть файл

@ -380,7 +380,7 @@ bool XPCConvert::NativeData2JS(MutableHandleValue d, const void* s,
}
xpcObjectHelper helper(iface);
return NativeInterface2JSObject(d, helper, iid, true, pErr);
return NativeInterface2JSObject(cx, d, helper, iid, true, pErr);
}
case nsXPTType::T_DOMOBJECT: {
@ -915,7 +915,7 @@ bool XPCConvert::JSData2Native(JSContext* cx, void* d, HandleValue s,
/***************************************************************************/
// static
bool XPCConvert::NativeInterface2JSObject(MutableHandleValue d,
bool XPCConvert::NativeInterface2JSObject(JSContext* cx, MutableHandleValue d,
xpcObjectHelper& aHelper,
const nsID* iid,
bool allowNativeWrapper,
@ -939,7 +939,6 @@ bool XPCConvert::NativeInterface2JSObject(MutableHandleValue d,
// (that means an XPCWrappedNative around an nsXPCWrappedJS). This isn't
// optimal -- we could detect this and roll the functionality into a
// single wrapper, but the current solution is good enough for now.
AutoJSContext cx;
XPCWrappedNativeScope* xpcscope = ObjectScope(JS::CurrentGlobalOrNull(cx));
if (!xpcscope) {
return false;

Просмотреть файл

@ -89,8 +89,8 @@ XPCWrappedNativeScope::XPCWrappedNativeScope(JS::Compartment* aCompartment,
mAllowContentXBLScope = !RemoteXULForbidsXBLScope(aFirstGlobal);
}
bool XPCWrappedNativeScope::GetComponentsJSObject(JS::MutableHandleObject obj) {
AutoJSContext cx;
bool XPCWrappedNativeScope::GetComponentsJSObject(JSContext* cx,
JS::MutableHandleObject obj) {
if (!mComponents) {
bool system = AccessCheck::isChrome(mCompartment);
mComponents =
@ -99,8 +99,8 @@ bool XPCWrappedNativeScope::GetComponentsJSObject(JS::MutableHandleObject obj) {
RootedValue val(cx);
xpcObjectHelper helper(mComponents);
bool ok = XPCConvert::NativeInterface2JSObject(&val, helper, nullptr, false,
nullptr);
bool ok = XPCConvert::NativeInterface2JSObject(cx, &val, helper, nullptr,
false, nullptr);
if (NS_WARN_IF(!ok)) {
return false;
}
@ -131,8 +131,8 @@ static bool DefineSubcomponentProperty(JSContext* aCx, HandleObject aGlobal,
unsigned int aStringIndex) {
RootedValue subcompVal(aCx);
xpcObjectHelper helper(aSubcomponent);
if (!XPCConvert::NativeInterface2JSObject(&subcompVal, helper, aIID, false,
nullptr))
if (!XPCConvert::NativeInterface2JSObject(aCx, &subcompVal, helper, aIID,
false, nullptr))
return false;
if (NS_WARN_IF(!subcompVal.isObject())) {
return false;
@ -143,7 +143,7 @@ static bool DefineSubcomponentProperty(JSContext* aCx, HandleObject aGlobal,
bool XPCWrappedNativeScope::AttachComponentsObject(JSContext* aCx) {
RootedObject components(aCx);
if (!GetComponentsJSObject(&components)) {
if (!GetComponentsJSObject(aCx, &components)) {
return false;
}

Просмотреть файл

@ -566,18 +566,17 @@ nsresult InitClassesWithNewWrappedGlobal(JSContext* aJSContext,
} // namespace xpc
static nsresult NativeInterface2JSObject(HandleObject aScope,
static nsresult NativeInterface2JSObject(JSContext* aCx, HandleObject aScope,
nsISupports* aCOMObj,
nsWrapperCache* aCache,
const nsIID* aIID, bool aAllowWrapping,
MutableHandleValue aVal) {
AutoJSContext cx;
JSAutoRealm ar(cx, aScope);
JSAutoRealm ar(aCx, aScope);
nsresult rv;
xpcObjectHelper helper(aCOMObj, aCache);
if (!XPCConvert::NativeInterface2JSObject(aVal, helper, aIID, aAllowWrapping,
&rv)) {
if (!XPCConvert::NativeInterface2JSObject(aCx, aVal, helper, aIID,
aAllowWrapping, &rv)) {
return rv;
}
@ -598,8 +597,8 @@ nsXPConnect::WrapNative(JSContext* aJSContext, JSObject* aScopeArg,
RootedObject aScope(aJSContext, aScopeArg);
RootedValue v(aJSContext);
nsresult rv =
NativeInterface2JSObject(aScope, aCOMObj, nullptr, &aIID, true, &v);
nsresult rv = NativeInterface2JSObject(aJSContext, aScope, aCOMObj, nullptr,
&aIID, true, &v);
if (NS_FAILED(rv)) {
return rv;
}
@ -622,8 +621,8 @@ nsXPConnect::WrapNativeToJSVal(JSContext* aJSContext, JSObject* aScopeArg,
MOZ_ASSERT(aCOMObj, "bad param");
RootedObject aScope(aJSContext, aScopeArg);
return NativeInterface2JSObject(aScope, aCOMObj, aCache, aIID, aAllowWrapping,
aVal);
return NativeInterface2JSObject(aJSContext, aScope, aCOMObj, aCache, aIID,
aAllowWrapping, aVal);
}
NS_IMETHODIMP

Просмотреть файл

@ -838,7 +838,7 @@ class XPCWrappedNativeScope final
bool AttachComponentsObject(JSContext* aCx);
// Returns the JS object reflection of the Components object.
bool GetComponentsJSObject(JS::MutableHandleObject obj);
bool GetComponentsJSObject(JSContext* cx, JS::MutableHandleObject obj);
JSObject* GetExpandoChain(JS::HandleObject target);
@ -1856,6 +1856,7 @@ class XPCConvert {
/**
* Convert a native nsISupports into a JSObject.
*
* @param cx the JSContext representing the global we want the object in.
* @param dest [out] the resulting JSObject
* @param src the native object we're working with
* @param iid the interface of src that we want (may be null)
@ -1867,7 +1868,8 @@ class XPCConvert {
* @param src_is_identity optional performance hint. Set to true only
* if src is the identity pointer.
*/
static bool NativeInterface2JSObject(JS::MutableHandleValue dest,
static bool NativeInterface2JSObject(JSContext* cx,
JS::MutableHandleValue dest,
xpcObjectHelper& aHelper,
const nsID* iid, bool allowNativeWrapper,
nsresult* pErr);