Bug 865961. Root the scope argument of wrap-the-xpconnect-object helpers in WebIDL bindings. r=ms2ger

This commit is contained in:
Boris Zbarsky 2013-04-29 17:33:42 -04:00
Родитель 3394bf9a4a
Коммит 9e0ae56b05
9 изменённых файлов: 52 добавлений и 44 удалений

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

@ -673,7 +673,7 @@ nsContentList::NamedItem(JSContext* cx, const nsAString& name,
if (!item) {
return nullptr;
}
JSObject* wrapper = GetWrapper();
JS::Rooted<JSObject*> wrapper(cx, GetWrapper());
JSAutoCompartment ac(cx, wrapper);
JS::Value v;
if (!mozilla::dom::WrapObject(cx, wrapper, item, item, nullptr, &v)) {

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

@ -1291,7 +1291,7 @@ CanvasRenderingContext2D::SetStyleFromJSValue(JSContext* cx,
}
static JS::Value
WrapStyle(JSContext* cx, JSObject* obj,
WrapStyle(JSContext* cx, JSObject* objArg,
CanvasRenderingContext2D::CanvasMultiGetterType type,
nsAString& str, nsISupports* supports, ErrorResult& error)
{
@ -1306,6 +1306,7 @@ WrapStyle(JSContext* cx, JSObject* obj,
case CanvasRenderingContext2D::CMG_STYLE_PATTERN:
case CanvasRenderingContext2D::CMG_STYLE_GRADIENT:
{
JS::Rooted<JSObject*> obj(cx, objArg);
ok = dom::WrapObject(cx, obj, supports, &v);
break;
}

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

@ -289,7 +289,7 @@ HTMLOptionsCollection::NamedItem(JSContext* cx, const nsAString& name,
if (!item) {
return nullptr;
}
JSObject* wrapper = nsWrapperCache::GetWrapper();
JS::Rooted<JSObject*> wrapper(cx, nsWrapperCache::GetWrapper());
JSAutoCompartment ac(cx, wrapper);
JS::Value v;
if (!mozilla::dom::WrapObject(cx, wrapper, item, item, nullptr, &v)) {

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

@ -232,7 +232,7 @@ TableRowsCollection::NamedItem(JSContext* cx, const nsAString& name,
return nullptr;
}
if (item) {
JSObject* wrapper = nsWrapperCache::GetWrapper();
JS::Rooted<JSObject*> wrapper(cx, nsWrapperCache::GetWrapper());
JSAutoCompartment ac(cx, wrapper);
JS::Value v;
if (!mozilla::dom::WrapObject(cx, wrapper, item, &v)) {

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

@ -3126,13 +3126,14 @@ JS::Value
nsGenericHTMLElement::GetItemValue(JSContext* aCx, JSObject* aScope,
ErrorResult& aError)
{
JS::Rooted<JSObject*> scope(aCx, aScope);
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::itemprop)) {
return JS::NullValue();
}
if (ItemScope()) {
JS::Value v;
if (!mozilla::dom::WrapObject(aCx, aScope, this, &v)) {
if (!mozilla::dom::WrapObject(aCx, scope, this, &v)) {
aError.Throw(NS_ERROR_FAILURE);
return JS::UndefinedValue();
}

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

@ -2551,7 +2551,7 @@ nsFormControlList::NamedItem(JSContext* cx, const nsAString& name,
if (!item) {
return nullptr;
}
JSObject* wrapper = nsWrapperCache::GetWrapper();
JS::Rooted<JSObject*> wrapper(cx, nsWrapperCache::GetWrapper());
JSAutoCompartment ac(cx, wrapper);
JS::Value v;
if (!mozilla::dom::WrapObject(cx, wrapper, item, &v)) {

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

@ -2369,7 +2369,7 @@ nsHTMLDocument::NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
JS::Value val;
{ // Scope for auto-compartment
JSObject* wrapper = GetWrapper();
JS::Rooted<JSObject*> wrapper(cx, GetWrapper());
JSAutoCompartment ac(cx, wrapper);
// XXXbz Should we call the (slightly misnamed, really) WrapNativeParent
// here?

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

@ -571,7 +571,7 @@ CreateInterfaceObjects(JSContext* cx, JSObject* global, JSObject* protoProto,
bool
NativeInterface2JSObjectAndThrowIfFailed(JSContext* aCx,
JSObject* aScope,
JS::Handle<JSObject*> aScope,
JS::Value* aRetval,
xpcObjectHelper& aHelper,
const nsIID* aIID,
@ -626,8 +626,9 @@ InstanceClassHasProtoAtDepth(JSHandleObject protoObject, uint32_t protoID,
// Only set allowNativeWrapper to false if you really know you need it, if in
// doubt use true. Setting it to false disables security wrappers.
bool
XPCOMObjectToJsval(JSContext* cx, JSObject* scope, xpcObjectHelper &helper,
const nsIID* iid, bool allowNativeWrapper, JS::Value* rval)
XPCOMObjectToJsval(JSContext* cx, JS::Handle<JSObject*> scope,
xpcObjectHelper& helper, const nsIID* iid,
bool allowNativeWrapper, JS::Value* rval)
{
if (!NativeInterface2JSObjectAndThrowIfFailed(cx, scope, rval, helper, iid,
allowNativeWrapper)) {
@ -645,8 +646,8 @@ XPCOMObjectToJsval(JSContext* cx, JSObject* scope, xpcObjectHelper &helper,
}
bool
VariantToJsval(JSContext* aCx, JSObject* aScope, nsIVariant* aVariant,
JS::Value* aRetval)
VariantToJsval(JSContext* aCx, JS::Handle<JSObject*> aScope,
nsIVariant* aVariant, JS::Value* aRetval)
{
nsresult rv;
XPCLazyCallContext lccx(JS_CALLER, aCx, aScope);
@ -665,12 +666,12 @@ JSBool
QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp)
{
JS::Value thisv = JS_THIS(cx, vp);
if (thisv == JSVAL_NULL)
if (thisv.isNull())
return false;
// Get the object. It might be a security wrapper, in which case we do a checked
// unwrap.
JSObject* origObj = JSVAL_TO_OBJECT(thisv);
JS::Rooted<JSObject*> origObj(cx, &thisv.toObject());
JSObject* obj = js::CheckedUnwrap(origObj);
if (!obj) {
JS_ReportError(cx, "Permission denied to access object");

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

@ -714,7 +714,7 @@ WrapNewBindingNonWrapperCachedObject(JSContext* cx, JS::Handle<JSObject*> scope,
// doubt use true. Setting it to false disables security wrappers.
bool
NativeInterface2JSObjectAndThrowIfFailed(JSContext* aCx,
JSObject* aScope,
JS::Handle<JSObject*> aScope,
JS::Value* aRetval,
xpcObjectHelper& aHelper,
const nsIID* aIID,
@ -726,8 +726,8 @@ NativeInterface2JSObjectAndThrowIfFailed(JSContext* aCx,
*/
template <class T>
MOZ_ALWAYS_INLINE bool
HandleNewBindingWrappingFailure(JSContext* cx, JSObject* scope, T* value,
JS::Value* vp)
HandleNewBindingWrappingFailure(JSContext* cx, JS::Handle<JSObject*> scope,
T* value, JS::Value* vp)
{
if (JS_IsExceptionPending(cx)) {
return false;
@ -745,8 +745,8 @@ HAS_MEMBER(get)
template <class T, bool isSmartPtr=HasgetMember<T>::Value>
struct HandleNewBindingWrappingFailureHelper
{
static inline bool Wrap(JSContext* cx, JSObject* scope, const T& value,
JS::Value* vp)
static inline bool Wrap(JSContext* cx, JS::Handle<JSObject*> scope,
const T& value, JS::Value* vp)
{
return HandleNewBindingWrappingFailure(cx, scope, value.get(), vp);
}
@ -755,7 +755,7 @@ struct HandleNewBindingWrappingFailureHelper
template <class T>
struct HandleNewBindingWrappingFailureHelper<T, false>
{
static inline bool Wrap(JSContext* cx, JSObject* scope, T& value,
static inline bool Wrap(JSContext* cx, JS::Handle<JSObject*> scope, T& value,
JS::Value* vp)
{
return HandleNewBindingWrappingFailure(cx, scope, &value, vp);
@ -764,8 +764,8 @@ struct HandleNewBindingWrappingFailureHelper<T, false>
template<class T>
inline bool
HandleNewBindingWrappingFailure(JSContext* cx, JSObject* scope, T& value,
JS::Value* vp)
HandleNewBindingWrappingFailure(JSContext* cx, JS::Handle<JSObject*> scope,
T& value, JS::Value* vp)
{
return HandleNewBindingWrappingFailureHelper<T>::Wrap(cx, scope, value, vp);
}
@ -896,13 +896,14 @@ InstanceClassHasProtoAtDepth(JSHandleObject protoObject, uint32_t protoID,
// Only set allowNativeWrapper to false if you really know you need it, if in
// doubt use true. Setting it to false disables security wrappers.
bool
XPCOMObjectToJsval(JSContext* cx, JSObject* scope, xpcObjectHelper &helper,
const nsIID* iid, bool allowNativeWrapper, JS::Value* rval);
XPCOMObjectToJsval(JSContext* cx, JS::Handle<JSObject*> scope,
xpcObjectHelper& helper, const nsIID* iid,
bool allowNativeWrapper, JS::Value* rval);
// Special-cased wrapping for variants
bool
VariantToJsval(JSContext* aCx, JSObject* aScope, nsIVariant* aVariant,
JS::Value* aRetval);
VariantToJsval(JSContext* aCx, JS::Handle<JSObject*> aScope,
nsIVariant* aVariant, JS::Value* aRetval);
// Wrap an object "p" which is not using WebIDL bindings yet. This _will_
// actually work on WebIDL binding objects that are wrappercached, but will be
@ -910,8 +911,8 @@ VariantToJsval(JSContext* aCx, JSObject* aScope, nsIVariant* aVariant,
// nsWrapperCache for "p".
template<class T>
inline bool
WrapObject(JSContext* cx, JSObject* scope, T* p, nsWrapperCache* cache,
const nsIID* iid, JS::Value* vp)
WrapObject(JSContext* cx, JS::Handle<JSObject*> scope, T* p,
nsWrapperCache* cache, const nsIID* iid, JS::Value* vp)
{
if (xpc_FastGetCachedWrapper(cache, scope, vp))
return true;
@ -923,7 +924,7 @@ WrapObject(JSContext* cx, JSObject* scope, T* p, nsWrapperCache* cache,
// do something different.
template<>
inline bool
WrapObject<nsIVariant>(JSContext* cx, JSObject* scope, nsIVariant* p,
WrapObject<nsIVariant>(JSContext* cx, JS::Handle<JSObject*> scope, nsIVariant* p,
nsWrapperCache* cache, const nsIID* iid, JS::Value* vp)
{
MOZ_ASSERT(iid);
@ -936,7 +937,7 @@ WrapObject<nsIVariant>(JSContext* cx, JSObject* scope, nsIVariant* p,
// nsWrapperCache* from "p".
template<class T>
inline bool
WrapObject(JSContext* cx, JSObject* scope, T* p, const nsIID* iid,
WrapObject(JSContext* cx, JS::Handle<JSObject*> scope, T* p, const nsIID* iid,
JS::Value* vp)
{
return WrapObject(cx, scope, p, GetWrapperCache(p), iid, vp);
@ -947,7 +948,7 @@ WrapObject(JSContext* cx, JSObject* scope, T* p, const nsIID* iid,
// classinfo, for which it doesn't matter what IID is used to wrap.
template<class T>
inline bool
WrapObject(JSContext* cx, JSObject* scope, T* p, JS::Value* vp)
WrapObject(JSContext* cx, JS::Handle<JSObject*> scope, T* p, JS::Value* vp)
{
return WrapObject(cx, scope, p, NULL, vp);
}
@ -955,8 +956,8 @@ WrapObject(JSContext* cx, JSObject* scope, T* p, JS::Value* vp)
// Helper to make it possible to wrap directly out of an nsCOMPtr
template<class T>
inline bool
WrapObject(JSContext* cx, JSObject* scope, const nsCOMPtr<T> &p, const nsIID* iid,
JS::Value* vp)
WrapObject(JSContext* cx, JS::Handle<JSObject*> scope, const nsCOMPtr<T>& p,
const nsIID* iid, JS::Value* vp)
{
return WrapObject(cx, scope, p.get(), iid, vp);
}
@ -964,7 +965,8 @@ WrapObject(JSContext* cx, JSObject* scope, const nsCOMPtr<T> &p, const nsIID* ii
// Helper to make it possible to wrap directly out of an nsCOMPtr
template<class T>
inline bool
WrapObject(JSContext* cx, JSObject* scope, const nsCOMPtr<T> &p, JS::Value* vp)
WrapObject(JSContext* cx, JS::Handle<JSObject*> scope, const nsCOMPtr<T>& p,
JS::Value* vp)
{
return WrapObject(cx, scope, p, NULL, vp);
}
@ -972,8 +974,8 @@ WrapObject(JSContext* cx, JSObject* scope, const nsCOMPtr<T> &p, JS::Value* vp)
// Helper to make it possible to wrap directly out of an nsRefPtr
template<class T>
inline bool
WrapObject(JSContext* cx, JSObject* scope, const nsRefPtr<T> &p, const nsIID* iid,
JS::Value* vp)
WrapObject(JSContext* cx, JS::Handle<JSObject*> scope, const nsRefPtr<T>& p,
const nsIID* iid, JS::Value* vp)
{
return WrapObject(cx, scope, p.get(), iid, vp);
}
@ -981,7 +983,8 @@ WrapObject(JSContext* cx, JSObject* scope, const nsRefPtr<T> &p, const nsIID* ii
// Helper to make it possible to wrap directly out of an nsRefPtr
template<class T>
inline bool
WrapObject(JSContext* cx, JSObject* scope, const nsRefPtr<T> &p, JS::Value* vp)
WrapObject(JSContext* cx, JS::Handle<JSObject*> scope, const nsRefPtr<T>& p,
JS::Value* vp)
{
return WrapObject(cx, scope, p, NULL, vp);
}
@ -989,14 +992,16 @@ WrapObject(JSContext* cx, JSObject* scope, const nsRefPtr<T> &p, JS::Value* vp)
// Specialization to make it easy to use WrapObject in codegen.
template<>
inline bool
WrapObject<JSObject>(JSContext* cx, JSObject* scope, JSObject* p, JS::Value* vp)
WrapObject<JSObject>(JSContext* cx, JS::Handle<JSObject*> scope, JSObject* p,
JS::Value* vp)
{
vp->setObjectOrNull(p);
return true;
}
inline bool
WrapObject(JSContext* cx, JSObject* scope, JSObject& p, JS::Value* vp)
WrapObject(JSContext* cx, JS::Handle<JSObject*> scope, JSObject& p,
JS::Value* vp)
{
vp->setObject(p);
return true;
@ -1008,7 +1013,7 @@ WrapObject(JSContext* cx, JSObject* scope, JSObject& p, JS::Value* vp)
// don't want those for our parent object.
template<typename T>
static inline JSObject*
WrapNativeISupportsParent(JSContext* cx, JSObject* scope, T* p,
WrapNativeISupportsParent(JSContext* cx, JS::Handle<JSObject*> scope, T* p,
nsWrapperCache* cache)
{
qsObjectHelper helper(ToSupports(p), cache);
@ -1023,8 +1028,8 @@ WrapNativeISupportsParent(JSContext* cx, JSObject* scope, T* p,
template<typename T, bool isISupports=IsISupports<T>::Value >
struct WrapNativeParentFallback
{
static inline JSObject* Wrap(JSContext* cx, JSObject* scope, T* parent,
nsWrapperCache* cache)
static inline JSObject* Wrap(JSContext* cx, JS::Handle<JSObject*> scope,
T* parent, nsWrapperCache* cache)
{
return nullptr;
}
@ -1035,8 +1040,8 @@ struct WrapNativeParentFallback
template<typename T >
struct WrapNativeParentFallback<T, true >
{
static inline JSObject* Wrap(JSContext* cx, JSObject* scope, T* parent,
nsWrapperCache* cache)
static inline JSObject* Wrap(JSContext* cx, JS::Handle<JSObject*> scope,
T* parent, nsWrapperCache* cache)
{
return WrapNativeISupportsParent(cx, scope, parent, cache);
}