Bug 1335368 part 8. Stop using IsCallerChrome in UnwrapArgImpl. r=bholley

This commit is contained in:
Boris Zbarsky 2017-02-01 15:43:37 -05:00
parent d9a60c022b
commit da79ef55fe
4 changed files with 21 additions and 16 deletions

View File

@ -1153,7 +1153,7 @@ QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp)
// Switch this to UnwrapDOMObjectToISupports once our global objects are
// using new bindings.
nsCOMPtr<nsISupports> native;
UnwrapArg<nsISupports>(obj, getter_AddRefs(native));
UnwrapArg<nsISupports>(cx, obj, getter_AddRefs(native));
if (!native) {
return Throw(cx, NS_ERROR_FAILURE);
}
@ -1168,7 +1168,7 @@ QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp)
nsCOMPtr<nsIJSID> iid;
obj = &args[0].toObject();
if (NS_FAILED(UnwrapArg<nsIJSID>(obj, getter_AddRefs(iid)))) {
if (NS_FAILED(UnwrapArg<nsIJSID>(cx, obj, getter_AddRefs(iid)))) {
return Throw(cx, NS_ERROR_XPC_BAD_CONVERT_JS);
}
MOZ_ASSERT(iid);
@ -3154,7 +3154,8 @@ CallerSubsumes(JSObject *aObject)
}
nsresult
UnwrapArgImpl(JS::Handle<JSObject*> src,
UnwrapArgImpl(JSContext* cx,
JS::Handle<JSObject*> src,
const nsIID &iid,
void **ppArg)
{
@ -3174,7 +3175,7 @@ UnwrapArgImpl(JS::Handle<JSObject*> src,
// Only allow XPCWrappedJS stuff in system code. Ideally we would remove this
// even there, but that involves converting some things to WebIDL callback
// interfaces and making some other things builtinclass...
if (!nsContentUtils::IsCallerChrome()) {
if (!nsContentUtils::IsSystemCaller(cx)) {
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
@ -3192,11 +3193,12 @@ UnwrapArgImpl(JS::Handle<JSObject*> src,
}
nsresult
UnwrapWindowProxyImpl(JS::Handle<JSObject*> src,
UnwrapWindowProxyImpl(JSContext* cx,
JS::Handle<JSObject*> src,
nsPIDOMWindowOuter** ppArg)
{
nsCOMPtr<nsPIDOMWindowInner> inner;
nsresult rv = UnwrapArg<nsPIDOMWindowInner>(src, getter_AddRefs(inner));
nsresult rv = UnwrapArg<nsPIDOMWindowInner>(cx, src, getter_AddRefs(inner));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsPIDOMWindowOuter> outer = inner->GetOuterWindow();

View File

@ -53,25 +53,28 @@ namespace dom {
template<typename DataType> class MozMap;
nsresult
UnwrapArgImpl(JS::Handle<JSObject*> src, const nsIID& iid, void** ppArg);
UnwrapArgImpl(JSContext* cx, JS::Handle<JSObject*> src, const nsIID& iid,
void** ppArg);
nsresult
UnwrapWindowProxyImpl(JS::Handle<JSObject*> src, nsPIDOMWindowOuter** ppArg);
UnwrapWindowProxyImpl(JSContext* cx, JS::Handle<JSObject*> src,
nsPIDOMWindowOuter** ppArg);
/** Convert a jsval to an XPCOM pointer. */
template <class Interface>
inline nsresult
UnwrapArg(JS::Handle<JSObject*> src, Interface** ppArg)
UnwrapArg(JSContext* cx, JS::Handle<JSObject*> src, Interface** ppArg)
{
return UnwrapArgImpl(src, NS_GET_TEMPLATE_IID(Interface),
return UnwrapArgImpl(cx, src, NS_GET_TEMPLATE_IID(Interface),
reinterpret_cast<void**>(ppArg));
}
template <>
inline nsresult
UnwrapArg<nsPIDOMWindowOuter>(JS::Handle<JSObject*> src, nsPIDOMWindowOuter** ppArg)
UnwrapArg<nsPIDOMWindowOuter>(JSContext* cx, JS::Handle<JSObject*> src,
nsPIDOMWindowOuter** ppArg)
{
return UnwrapWindowProxyImpl(src, ppArg);
return UnwrapWindowProxyImpl(cx, src, ppArg);
}
bool

View File

@ -4243,7 +4243,7 @@ class CastableObjectUnwrapper():
// want to be in that compartment for the UnwrapArg call.
JS::Rooted<JSObject*> source(cx, ${source});
JSAutoCompartment ac(cx, ${source});
rv = UnwrapArg<${type}>(source, getter_AddRefs(objPtr));
rv = UnwrapArg<${type}>(cx, source, getter_AddRefs(objPtr));
}
""")
else:
@ -4251,7 +4251,7 @@ class CastableObjectUnwrapper():
self.substitution["source"] = source
xpconnectUnwrap = (
"JS::Rooted<JSObject*> source(cx, ${source});\n"
"nsresult rv = UnwrapArg<${type}>(source, getter_AddRefs(objPtr));\n")
"nsresult rv = UnwrapArg<${type}>(cx, source, getter_AddRefs(objPtr));\n")
if descriptor.hasXPConnectImpls:
self.substitution["codeOnFailure"] = string.Template(
@ -5503,7 +5503,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
holderType = "RefPtr<" + typeName + ">"
templateBody += (
"JS::Rooted<JSObject*> source(cx, &${val}.toObject());\n" +
"if (NS_FAILED(UnwrapArg<" + typeName + ">(source, getter_AddRefs(${holderName})))) {\n")
"if (NS_FAILED(UnwrapArg<" + typeName + ">(cx, source, getter_AddRefs(${holderName})))) {\n")
templateBody += CGIndenter(onFailureBadType(failureCode,
descriptor.interface.identifier.name)).define()
templateBody += ("}\n"

View File

@ -431,7 +431,7 @@ WrapperOwner::DOMQI(JSContext* cx, JS::HandleObject proxy, JS::CallArgs& args)
RootedObject idobj(cx, &id.toObject());
nsCOMPtr<nsIJSID> jsid;
nsresult rv = UnwrapArg<nsIJSID>(idobj, getter_AddRefs(jsid));
nsresult rv = UnwrapArg<nsIJSID>(cx, idobj, getter_AddRefs(jsid));
if (NS_SUCCEEDED(rv)) {
MOZ_ASSERT(jsid, "bad wrapJS");
const nsID* idptr = jsid->GetID();