Bug 906940 - Exactly root the IsAcceptableThis callback; r=jonco,smaug

--HG--
extra : rebase_source : 3b629611a07fc52a532a05c1b56e5aa40b6a67b6
This commit is contained in:
Terrence Cole 2013-05-28 11:23:04 -07:00
parent fc0c74d682
commit 24ea5a25b4
17 changed files with 51 additions and 42 deletions

View File

@ -105,7 +105,7 @@ static const uint32_t XBLPROTO_SLOT = 0;
static const uint32_t FIELD_SLOT = 1;
bool
ValueHasISupportsPrivate(const JS::Value &v)
ValueHasISupportsPrivate(JS::Handle<JS::Value> v)
{
if (!v.isObject()) {
return false;
@ -122,6 +122,15 @@ ValueHasISupportsPrivate(const JS::Value &v)
return (clasp->flags & HAS_PRIVATE_NSISUPPORTS) == HAS_PRIVATE_NSISUPPORTS;
}
#ifdef DEBUG
static bool
ValueHasISupportsPrivate(JSContext* cx, const JS::Value& aVal)
{
JS::Rooted<JS::Value> v(cx, aVal);
return ValueHasISupportsPrivate(v);
}
#endif
// Define a shadowing property on |this| for the XBL field defined by the
// contents of the callee's reserved slots. If the property was defined,
// *installed will be true, and idp will be set to the property name that was
@ -137,7 +146,7 @@ InstallXBLField(JSContext* cx,
//
// FieldAccessorGuard already determined whether |thisObj| was acceptable as
// |this| in terms of not throwing a TypeError. Assert this for good measure.
MOZ_ASSERT(ValueHasISupportsPrivate(JS::ObjectValue(*thisObj)));
MOZ_ASSERT(ValueHasISupportsPrivate(cx, JS::ObjectValue(*thisObj)));
// But there are some cases where we must accept |thisObj| but not install a
// property on it, or otherwise touch it. Hence this split of |this|-vetting
@ -222,7 +231,7 @@ InstallXBLField(JSContext* cx,
bool
FieldGetterImpl(JSContext *cx, JS::CallArgs args)
{
const JS::Value &thisv = args.thisv();
JS::Handle<JS::Value> thisv = args.thisv();
MOZ_ASSERT(ValueHasISupportsPrivate(thisv));
JS::Rooted<JSObject*> thisObj(cx, &thisv.toObject());
@ -263,7 +272,7 @@ FieldGetter(JSContext *cx, unsigned argc, JS::Value *vp)
bool
FieldSetterImpl(JSContext *cx, JS::CallArgs args)
{
const JS::Value &thisv = args.thisv();
JS::Handle<JS::Value> thisv = args.thisv();
MOZ_ASSERT(ValueHasISupportsPrivate(thisv));
JS::Rooted<JSObject*> thisObj(cx, &thisv.toObject());

View File

@ -866,7 +866,7 @@ class MapIteratorObject : public JSObject
static void finalize(FreeOp *fop, JSObject *obj);
private:
static inline bool is(const Value &v);
static inline bool is(HandleValue v);
inline ValueMap::Range *range();
inline MapObject::IteratorKind kind() const;
static bool next_impl(JSContext *cx, CallArgs args);
@ -956,7 +956,7 @@ MapIteratorObject::finalize(FreeOp *fop, JSObject *obj)
}
bool
MapIteratorObject::is(const Value &v)
MapIteratorObject::is(HandleValue v)
{
return v.isObject() && v.toObject().hasClass(&class_);
}
@ -1208,7 +1208,7 @@ MapObject::construct(JSContext *cx, unsigned argc, Value *vp)
}
bool
MapObject::is(const Value &v)
MapObject::is(HandleValue v)
{
return v.isObject() && v.toObject().hasClass(&class_) && v.toObject().getPrivate();
}
@ -1433,7 +1433,7 @@ class SetIteratorObject : public JSObject
static void finalize(FreeOp *fop, JSObject *obj);
private:
static inline bool is(const Value &v);
static inline bool is(HandleValue v);
inline ValueSet::Range *range();
inline SetObject::IteratorKind kind() const;
static bool next_impl(JSContext *cx, CallArgs args);
@ -1522,7 +1522,7 @@ SetIteratorObject::finalize(FreeOp *fop, JSObject *obj)
}
bool
SetIteratorObject::is(const Value &v)
SetIteratorObject::is(HandleValue v)
{
return v.isObject() && v.toObject().is<SetIteratorObject>();
}
@ -1683,7 +1683,7 @@ SetObject::construct(JSContext *cx, unsigned argc, Value *vp)
}
bool
SetObject::is(const Value &v)
SetObject::is(HandleValue v)
{
return v.isObject() && v.toObject().hasClass(&class_) && v.toObject().getPrivate();
}

View File

@ -99,7 +99,7 @@ class MapObject : public JSObject {
static void finalize(FreeOp *fop, JSObject *obj);
static bool construct(JSContext *cx, unsigned argc, Value *vp);
static bool is(const Value &v);
static bool is(HandleValue v);
static bool iterator_impl(JSContext *cx, CallArgs args, IteratorKind kind);
@ -137,7 +137,7 @@ class SetObject : public JSObject {
static void finalize(FreeOp *fop, JSObject *obj);
static bool construct(JSContext *cx, unsigned argc, Value *vp);
static bool is(const Value &v);
static bool is(HandleValue v);
static bool iterator_impl(JSContext *cx, CallArgs args, IteratorKind kind);

View File

@ -305,7 +305,7 @@ CompileRegExpObject(JSContext *cx, RegExpObjectBuilder &builder, CallArgs args)
}
JS_ALWAYS_INLINE bool
IsRegExp(const Value &v)
IsRegExp(HandleValue v)
{
return v.isObject() && v.toObject().is<RegExpObject>();
}

View File

@ -21,7 +21,7 @@ static JSClass CustomClass = {
static const uint32_t CUSTOM_SLOT = 0;
static bool
IsCustomClass(const Value &v)
IsCustomClass(JS::Handle<JS::Value> v)
{
return v.isObject() && JS_GetClass(&v.toObject()) == &CustomClass;
}

View File

@ -104,7 +104,7 @@ bool
JS::detail::CallMethodIfWrapped(JSContext *cx, IsAcceptableThis test, NativeImpl impl,
CallArgs args)
{
const Value &thisv = args.thisv();
HandleValue thisv = args.thisv();
JS_ASSERT(!test(thisv));
if (thisv.isObject()) {

View File

@ -644,7 +644,7 @@ class JS_PUBLIC_API(CustomAutoRooter) : private AutoGCRooter
};
/* Returns true if |v| is considered an acceptable this-value. */
typedef bool (*IsAcceptableThis)(const Value &v);
typedef bool (*IsAcceptableThis)(JS::Handle<JS::Value> v);
/*
* Implements the guts of a method; guaranteed to be provided an acceptable
@ -728,7 +728,7 @@ template<IsAcceptableThis Test, NativeImpl Impl>
JS_ALWAYS_INLINE bool
CallNonGenericMethod(JSContext *cx, CallArgs args)
{
const Value &thisv = args.thisv();
HandleValue thisv = args.thisv();
if (Test(thisv))
return Impl(cx, args);
@ -738,7 +738,7 @@ CallNonGenericMethod(JSContext *cx, CallArgs args)
JS_ALWAYS_INLINE bool
CallNonGenericMethod(JSContext *cx, IsAcceptableThis Test, NativeImpl Impl, CallArgs args)
{
const Value &thisv = args.thisv();
HandleValue thisv = args.thisv();
if (Test(thisv))
return Impl(cx, args);

View File

@ -799,7 +799,7 @@ AddLengthProperty(ExclusiveContext *cx, HandleObject obj)
#if JS_HAS_TOSOURCE
JS_ALWAYS_INLINE bool
IsArray(const Value &v)
IsArray(HandleValue v)
{
return v.isObject() && v.toObject().is<ArrayObject>();
}

View File

@ -38,7 +38,7 @@ Class BooleanObject::class_ = {
};
JS_ALWAYS_INLINE bool
IsBoolean(const Value &v)
IsBoolean(HandleValue v)
{
return v.isBoolean() || (v.isObject() && v.toObject().is<BooleanObject>());
}
@ -47,7 +47,7 @@ IsBoolean(const Value &v)
JS_ALWAYS_INLINE bool
bool_toSource_impl(JSContext *cx, CallArgs args)
{
const Value &thisv = args.thisv();
HandleValue thisv = args.thisv();
JS_ASSERT(IsBoolean(thisv));
bool b = thisv.isBoolean() ? thisv.toBoolean() : thisv.toObject().as<BooleanObject>().unbox();
@ -74,7 +74,7 @@ bool_toSource(JSContext *cx, unsigned argc, Value *vp)
JS_ALWAYS_INLINE bool
bool_toString_impl(JSContext *cx, CallArgs args)
{
const Value &thisv = args.thisv();
HandleValue thisv = args.thisv();
JS_ASSERT(IsBoolean(thisv));
bool b = thisv.isBoolean() ? thisv.toBoolean() : thisv.toObject().as<BooleanObject>().unbox();
@ -92,7 +92,7 @@ bool_toString(JSContext *cx, unsigned argc, Value *vp)
JS_ALWAYS_INLINE bool
bool_valueOf_impl(JSContext *cx, CallArgs args)
{
const Value &thisv = args.thisv();
HandleValue thisv = args.thisv();
JS_ASSERT(IsBoolean(thisv));
bool b = thisv.isBoolean() ? thisv.toBoolean() : thisv.toObject().as<BooleanObject>().unbox();

View File

@ -1386,7 +1386,7 @@ DateObject::cachedLocalTime(DateTimeInfo *dtInfo)
}
JS_ALWAYS_INLINE bool
IsDate(const Value &v)
IsDate(HandleValue v)
{
return v.isObject() && v.toObject().is<DateObject>();
}

View File

@ -763,7 +763,7 @@ js::IteratorConstructor(JSContext *cx, unsigned argc, Value *vp)
}
JS_ALWAYS_INLINE bool
IsIterator(const Value &v)
IsIterator(HandleValue v)
{
return v.isObject() && v.toObject().hasClass(&PropertyIteratorObject::class_);
}
@ -876,7 +876,7 @@ ElementIteratorObject::create(JSContext *cx, Handle<Value> target)
}
static bool
IsElementIterator(const Value &v)
IsElementIterator(HandleValue v)
{
return v.isObject() && v.toObject().is<ElementIteratorObject>();
}
@ -1633,7 +1633,7 @@ CloseGenerator(JSContext *cx, HandleObject obj)
}
JS_ALWAYS_INLINE bool
IsGenerator(const Value &v)
IsGenerator(HandleValue v)
{
return v.isObject() && v.toObject().is<GeneratorObject>();
}

View File

@ -483,7 +483,7 @@ Number(JSContext *cx, unsigned argc, Value *vp)
}
JS_ALWAYS_INLINE bool
IsNumber(const Value &v)
IsNumber(HandleValue v)
{
return v.isNumber() || (v.isObject() && v.toObject().is<NumberObject>());
}

View File

@ -460,7 +460,7 @@ ThisToStringForStringProto(JSContext *cx, CallReceiver call)
}
JS_ALWAYS_INLINE bool
IsString(const Value &v)
IsString(HandleValue v)
{
return v.isString() || (v.isObject() && v.toObject().is<StringObject>());
}

View File

@ -126,7 +126,7 @@ GetKeyArg(JSContext *cx, CallArgs &args)
}
JS_ALWAYS_INLINE bool
IsWeakMap(const Value &v)
IsWeakMap(HandleValue v)
{
return v.isObject() && v.toObject().is<WeakMapObject>();
}

View File

@ -53,7 +53,7 @@ ThrowTypeError(JSContext *cx, unsigned argc, Value *vp)
}
static bool
TestProtoGetterThis(const Value &v)
TestProtoGetterThis(HandleValue v)
{
return !v.isNullOrUndefined();
}
@ -63,7 +63,7 @@ ProtoGetterImpl(JSContext *cx, CallArgs args)
{
JS_ASSERT(TestProtoGetterThis(args.thisv()));
const Value &thisv = args.thisv();
HandleValue thisv = args.thisv();
if (thisv.isPrimitive() && !BoxNonStrictThis(cx, args))
return false;
@ -90,7 +90,7 @@ size_t sSetProtoCalled = 0;
} // namespace js
static bool
TestProtoSetterThis(const Value &v)
TestProtoSetterThis(HandleValue v)
{
if (v.isNullOrUndefined())
return false;
@ -108,7 +108,7 @@ ProtoSetterImpl(JSContext *cx, CallArgs args)
{
JS_ASSERT(TestProtoSetterThis(args.thisv()));
const Value &thisv = args.thisv();
HandleValue thisv = args.thisv();
if (thisv.isPrimitive()) {
JS_ASSERT(!thisv.isNullOrUndefined());

View File

@ -124,7 +124,7 @@ ToClampedIndex(JSContext *cx, HandleValue v, uint32_t length, uint32_t *out)
*/
JS_ALWAYS_INLINE bool
IsArrayBuffer(const Value &v)
IsArrayBuffer(HandleValue v)
{
return v.isObject() && v.toObject().hasClass(&ArrayBufferObject::class_);
}
@ -1441,7 +1441,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject
return &TypedArrayObject::classes[ArrayTypeID()];
}
static bool is(const Value &v) {
static bool is(HandleValue v) {
return v.isObject() && v.toObject().hasClass(fastClass());
}
@ -1895,7 +1895,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject
return fromBuffer(cx, dataObj, byteOffset, length, proto);
}
static bool IsThisClass(const Value &v) {
static bool IsThisClass(HandleValue v) {
return v.isObject() && v.toObject().hasClass(fastClass());
}
@ -3984,7 +3984,7 @@ js_InitTypedArrayClasses(JSContext *cx, HandleObject obj)
}
bool
js::IsTypedArrayConstructor(const Value &v, uint32_t type)
js::IsTypedArrayConstructor(HandleValue v, uint32_t type)
{
switch (type) {
case TypedArrayObject::TYPE_INT8:
@ -4010,7 +4010,7 @@ js::IsTypedArrayConstructor(const Value &v, uint32_t type)
}
bool
js::IsTypedArrayBuffer(const Value &v)
js::IsTypedArrayBuffer(HandleValue v)
{
return v.isObject() && v.toObject().is<ArrayBufferObject>();
}

View File

@ -415,10 +415,10 @@ IsTypedArrayProtoClass(const Class *clasp)
}
bool
IsTypedArrayConstructor(const Value &v, uint32_t type);
IsTypedArrayConstructor(HandleValue v, uint32_t type);
bool
IsTypedArrayBuffer(const Value &v);
IsTypedArrayBuffer(HandleValue v);
static inline unsigned
TypedArrayShift(ArrayBufferView::ViewType viewType)
@ -450,7 +450,7 @@ class DataViewObject : public ArrayBufferViewObject
private:
static Class protoClass;
static bool is(const Value &v) {
static bool is(HandleValue v) {
return v.isObject() && v.toObject().hasClass(&class_);
}