diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index fb5733ae7bc3..a26e1bb76dd7 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -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 diff --git a/js/xpconnect/src/XPCConvert.cpp b/js/xpconnect/src/XPCConvert.cpp index 0559f4c01ac6..d82a064aae1c 100644 --- a/js/xpconnect/src/XPCConvert.cpp +++ b/js/xpconnect/src/XPCConvert.cpp @@ -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; diff --git a/js/xpconnect/src/XPCWrappedNativeScope.cpp b/js/xpconnect/src/XPCWrappedNativeScope.cpp index bcdb07855216..10e5b5a8462d 100644 --- a/js/xpconnect/src/XPCWrappedNativeScope.cpp +++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp @@ -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; } diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index d49ae14bc5a9..b6b52698e198 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -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 diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 88fc0837c058..a8dd38431ef2 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -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);