Bug 697343 - Remove getElementIfPresent. r=Waldo

This commit is contained in:
Tom Schuster 2013-12-05 20:07:24 +01:00
parent 743f9da9f1
commit b053653c80
18 changed files with 13 additions and 286 deletions

View File

@ -8284,66 +8284,6 @@ class CGDOMJSProxyHandler_finalize(ClassMethod):
return ("%s self = UnwrapProxy(proxy);\n\n" % (self.descriptor.nativeType + "*") +
finalizeHook(self.descriptor, FINALIZE_HOOK_NAME, self.args[0].name).define())
class CGDOMJSProxyHandler_getElementIfPresent(ClassMethod):
def __init__(self, descriptor):
args = [Argument('JSContext*', 'cx'),
Argument('JS::Handle<JSObject*>', 'proxy'),
Argument('JS::Handle<JSObject*>', 'receiver'),
Argument('uint32_t', 'index'),
Argument('JS::MutableHandle<JS::Value>', 'vp'),
Argument('bool*', 'present')]
ClassMethod.__init__(self, "getElementIfPresent", "bool", args)
self.descriptor = descriptor
def getBody(self):
successCode = ("*present = found;\n"
"return true;")
templateValues = {'jsvalRef': 'vp', 'jsvalHandle': 'vp',
'obj': 'proxy', 'successCode': successCode}
if self.descriptor.supportsIndexedProperties():
get = (CGProxyIndexedGetter(self.descriptor, templateValues).define() + "\n"
"// We skip the expando object and any named getters if\n"
"// there is an indexed getter.\n" +
"\n") % (self.descriptor.nativeType)
else:
if self.descriptor.supportsNamedProperties():
get = CGProxyNamedGetter(self.descriptor, templateValues,
"UINT_TO_JSVAL(index)").define()
get += """
JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy));
if (expando) {
bool isPresent;
if (!JS_GetElementIfPresent(cx, expando, index, expando, vp, &isPresent)) {
return false;
}
if (isPresent) {
*present = true;
return true;
}
}
"""
return """MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
"Should not have a XrayWrapper here");
""" + get + """
JS::Rooted<JSObject*> proto(cx);
if (!js::GetObjectProto(cx, proxy, &proto)) {
return false;
}
if (proto) {
bool isPresent;
if (!JS_GetElementIfPresent(cx, proto, index, proxy, vp, &isPresent)) {
return false;
}
*present = isPresent;
return true;
}
*present = false;
// Can't Debug_SetValueRangeToCrashOnTouch because it's not public
return true;"""
class CGDOMJSProxyHandler_getInstance(ClassMethod):
def __init__(self):
ClassMethod.__init__(self, "getInstance", "DOMProxyHandler*", [], static=True)
@ -8366,7 +8306,6 @@ class CGDOMJSProxyHandler(CGClass):
CGDOMJSProxyHandler_className(descriptor),
CGDOMJSProxyHandler_finalizeInBackground(descriptor),
CGDOMJSProxyHandler_finalize(descriptor),
CGDOMJSProxyHandler_getElementIfPresent(descriptor),
CGDOMJSProxyHandler_getInstance(),
CGDOMJSProxyHandler_delete(descriptor)]
CGClass.__init__(self, 'DOMProxyHandler',

View File

@ -347,9 +347,6 @@ typedef bool
(* ElementIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver, uint32_t index,
JS::MutableHandleValue vp);
typedef bool
(* ElementIfPresentOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver,
uint32_t index, JS::MutableHandleValue vp, bool* present);
typedef bool
(* SpecialIdOp)(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver,
HandleSpecialId sid, JS::MutableHandleValue vp);
typedef bool
@ -459,7 +456,6 @@ struct ObjectOps
GenericIdOp getGeneric;
PropertyIdOp getProperty;
ElementIdOp getElement;
ElementIfPresentOp getElementIfPresent; /* can be null */
SpecialIdOp getSpecial;
StrictGenericIdOp setGeneric;
StrictPropertyIdOp setProperty;
@ -480,7 +476,7 @@ struct ObjectOps
#define JS_NULL_OBJECT_OPS \
{nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, \
nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, \
nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr}
nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr}
} // namespace js

View File

@ -2054,15 +2054,6 @@ TypedDatum::obj_getProperty(JSContext *cx, HandleObject obj, HandleObject receiv
bool
TypedDatum::obj_getElement(JSContext *cx, HandleObject obj, HandleObject receiver,
uint32_t index, MutableHandleValue vp)
{
bool present;
return obj_getElementIfPresent(cx, obj, receiver, index, vp, &present);
}
bool
TypedDatum::obj_getElementIfPresent(JSContext *cx, HandleObject obj,
HandleObject receiver, uint32_t index,
MutableHandleValue vp, bool *present)
{
RootedObject type(cx, GetType(*obj));
TypeRepresentation *typeRepr = typeRepresentation(*type);
@ -2075,7 +2066,6 @@ TypedDatum::obj_getElementIfPresent(JSContext *cx, HandleObject obj,
break;
case TypeRepresentation::Array: {
*present = true;
ArrayTypeRepresentation *arrayTypeRepr = typeRepr->asArray();
if (index >= arrayTypeRepr->length()) {
@ -2091,12 +2081,11 @@ TypedDatum::obj_getElementIfPresent(JSContext *cx, HandleObject obj,
RootedObject proto(cx, obj->getProto());
if (!proto) {
*present = false;
vp.setUndefined();
return true;
}
return JSObject::getElementIfPresent(cx, proto, receiver, index, vp, present);
return JSObject::getElement(cx, proto, receiver, index, vp);
}
bool
@ -2461,7 +2450,6 @@ const Class TypedObject::class_ = {
TypedDatum::obj_getGeneric,
TypedDatum::obj_getProperty,
TypedDatum::obj_getElement,
TypedDatum::obj_getElementIfPresent,
TypedDatum::obj_getSpecial,
TypedDatum::obj_setGeneric,
TypedDatum::obj_setProperty,
@ -2553,7 +2541,6 @@ const Class TypedHandle::class_ = {
TypedDatum::obj_getGeneric,
TypedDatum::obj_getProperty,
TypedDatum::obj_getElement,
TypedDatum::obj_getElementIfPresent,
TypedDatum::obj_getSpecial,
TypedDatum::obj_setGeneric,
TypedDatum::obj_setProperty,

View File

@ -268,9 +268,6 @@ class TypedDatum : public JSObject
static bool obj_getSpecial(JSContext *cx, HandleObject obj, HandleObject receiver,
HandleSpecialId sid, MutableHandleValue vp);
static bool obj_getElementIfPresent(JSContext *cx, HandleObject obj,
HandleObject receiver, uint32_t index,
MutableHandleValue vp, bool *present);
static bool obj_setGeneric(JSContext *cx, HandleObject obj, HandleId id,
MutableHandleValue vp, bool strict);
static bool obj_setProperty(JSContext *cx, HandleObject obj, HandlePropertyName name,

View File

@ -3393,25 +3393,6 @@ JS_ForwardGetElementTo(JSContext *cx, JSObject *objArg, uint32_t index, JSObject
return JSObject::getElement(cx, obj, onBehalfOf, index, vp);
}
JS_PUBLIC_API(bool)
JS_GetElementIfPresent(JSContext *cx, JSObject *objArg, uint32_t index, JSObject *onBehalfOfArg,
MutableHandleValue vp, bool* present)
{
RootedObject obj(cx, objArg);
RootedObject onBehalfOf(cx, onBehalfOfArg);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj);
JSAutoResolveFlags rf(cx, 0);
bool isPresent;
if (!JSObject::getElementIfPresent(cx, obj, onBehalfOf, index, vp, &isPresent))
return false;
*present = isPresent;
return true;
}
JS_PUBLIC_API(bool)
JS_GetProperty(JSContext *cx, JSObject *objArg, const char *name, MutableHandleValue vp)
{

View File

@ -3040,15 +3040,6 @@ extern JS_PUBLIC_API(bool)
JS_ForwardGetElementTo(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf,
JS::MutableHandle<JS::Value> vp);
/*
* Get the property with name given by |index|, if it has one. If
* not, |*present| will be set to false and the value of |vp| must not
* be relied on.
*/
extern JS_PUBLIC_API(bool)
JS_GetElementIfPresent(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf,
JS::MutableHandle<JS::Value> vp, bool* present);
extern JS_PUBLIC_API(bool)
JS_SetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandle<JS::Value> vp);

View File

@ -134,7 +134,7 @@ js::StringIsArrayIndex(JSLinearString *str, uint32_t *indexp)
}
static bool
DoubleIndexToId(JSContext *cx, double index, MutableHandleId id)
ToId(JSContext *cx, double index, MutableHandleId id)
{
if (index == uint32_t(index))
return IndexToId(cx, uint32_t(index), id.address());
@ -143,18 +143,25 @@ DoubleIndexToId(JSContext *cx, double index, MutableHandleId id)
return ValueToId<CanGC>(cx, HandleValue::fromMarkedLocation(&tmp), id);
}
static bool
ToId(JSContext *cx, uint32_t index, MutableHandleId id)
{
return IndexToId(cx, index, id.address());
}
/*
* If the property at the given index exists, get its value into location
* pointed by vp and set *hole to false. Otherwise set *hole to true and *vp
* to JSVAL_VOID. This function assumes that the location pointed by vp is
* properly rooted and can be used as GC-protected storage for temporaries.
*/
template<typename IndexType>
static inline bool
DoGetElement(JSContext *cx, HandleObject obj, double index, bool *hole, MutableHandleValue vp)
DoGetElement(JSContext *cx, HandleObject obj, IndexType index, bool *hole, MutableHandleValue vp)
{
RootedId id(cx);
if (!DoubleIndexToId(cx, index, &id))
if (!ToId(cx, index, &id))
return false;
RootedObject obj2(cx);
@ -173,20 +180,6 @@ DoGetElement(JSContext *cx, HandleObject obj, double index, bool *hole, MutableH
return true;
}
static inline bool
DoGetElement(JSContext *cx, HandleObject obj, uint32_t index, bool *hole, MutableHandleValue vp)
{
bool present;
if (!JSObject::getElementIfPresent(cx, obj, obj, index, vp, &present))
return false;
*hole = !present;
if (*hole)
vp.setUndefined();
return true;
}
template<typename IndexType>
static void
AssertGreaterThanZero(IndexType index)
@ -296,7 +289,7 @@ SetArrayElement(JSContext *cx, HandleObject obj, double index, HandleValue v)
}
RootedId id(cx);
if (!DoubleIndexToId(cx, index, &id))
if (!ToId(cx, index, &id))
return false;
RootedValue tmp(cx, v);

View File

@ -1030,12 +1030,6 @@ class JSObject : public js::ObjectImpl
static inline bool getElementNoGC(JSContext *cx, JSObject *obj, JSObject *receiver,
uint32_t index, js::Value *vp);
/* If element is not present (e.g. array hole) *present is set to
false and the contents of *vp are unusable garbage. */
static inline bool getElementIfPresent(JSContext *cx, js::HandleObject obj,
js::HandleObject receiver, uint32_t index,
js::MutableHandleValue vp, bool *present);
static bool getSpecial(JSContext *cx, js::HandleObject obj,
js::HandleObject receiver, js::SpecialId sid,
js::MutableHandleValue vp)

View File

@ -583,38 +583,6 @@ JSObject::getElementNoGC(JSContext *cx, JSObject *obj, JSObject *receiver,
return getGenericNoGC(cx, obj, receiver, id, vp);
}
/* static */ inline bool
JSObject::getElementIfPresent(JSContext *cx, js::HandleObject obj, js::HandleObject receiver,
uint32_t index, js::MutableHandleValue vp,
bool *present)
{
js::ElementIfPresentOp op = obj->getOps()->getElementIfPresent;
if (op)
return op(cx, obj, receiver, index, vp, present);
/*
* For now, do the index-to-id conversion just once, then use
* lookupGeneric/getGeneric. Once lookupElement and getElement stop both
* doing index-to-id conversions, we can use those here.
*/
JS::RootedId id(cx);
if (!js::IndexToId(cx, index, id.address()))
return false;
JS::RootedObject obj2(cx);
js::RootedShape prop(cx);
if (!lookupGeneric(cx, obj, id, &obj2, &prop))
return false;
if (!prop) {
*present = false;
return true;
}
*present = true;
return getGeneric(cx, obj, receiver, id, vp);
}
inline js::GlobalObject &
JSObject::global() const
{

View File

@ -151,27 +151,6 @@ BaseProxyHandler::get(JSContext *cx, HandleObject proxy, HandleObject receiver,
return CallJSPropertyOp(cx, desc.getter(), receiver, id, vp);
}
bool
BaseProxyHandler::getElementIfPresent(JSContext *cx, HandleObject proxy, HandleObject receiver,
uint32_t index, MutableHandleValue vp, bool *present)
{
RootedId id(cx);
if (!IndexToId(cx, index, id.address()))
return false;
assertEnteredPolicy(cx, proxy, id);
if (!has(cx, proxy, id, present))
return false;
if (!*present) {
Debug_SetValueRangeToCrashOnTouch(vp.address(), 1);
return true;
}
return get(cx, proxy, receiver, id, vp);
}
bool
BaseProxyHandler::set(JSContext *cx, HandleObject proxy, HandleObject receiver,
HandleId id, bool strict, MutableHandleValue vp)
@ -2519,41 +2498,6 @@ Proxy::callProp(JSContext *cx, HandleObject proxy, HandleObject receiver, Handle
return true;
}
bool
Proxy::getElementIfPresent(JSContext *cx, HandleObject proxy, HandleObject receiver, uint32_t index,
MutableHandleValue vp, bool *present)
{
JS_CHECK_RECURSION(cx, return false);
RootedId id(cx);
if (!IndexToId(cx, index, id.address()))
return false;
BaseProxyHandler *handler = proxy->as<ProxyObject>().handler();
AutoEnterPolicy policy(cx, handler, proxy, id, BaseProxyHandler::GET, true);
if (!policy.allowed())
return policy.returnValue();
if (!handler->hasPrototype()) {
return handler->getElementIfPresent(cx, proxy, receiver, index,
vp, present);
}
bool hasOwn;
if (!handler->hasOwn(cx, proxy, id, &hasOwn))
return false;
if (hasOwn) {
*present = true;
return proxy->as<ProxyObject>().handler()->get(cx, proxy, receiver, id, vp);
}
*present = false;
INVOKE_ON_PROTOTYPE(cx, handler, proxy,
JSObject::getElementIfPresent(cx, proto, receiver, index, vp, present));
}
bool
Proxy::set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, bool strict,
MutableHandleValue vp)
@ -2891,13 +2835,6 @@ proxy_GetElement(JSContext *cx, HandleObject obj, HandleObject receiver, uint32_
return proxy_GetGeneric(cx, obj, receiver, id, vp);
}
static bool
proxy_GetElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver, uint32_t index,
MutableHandleValue vp, bool *present)
{
return Proxy::getElementIfPresent(cx, obj, receiver, index, vp, present);
}
static bool
proxy_GetSpecial(JSContext *cx, HandleObject obj, HandleObject receiver, HandleSpecialId sid,
MutableHandleValue vp)
@ -3128,7 +3065,6 @@ proxy_Unwatch(JSContext *cx, JS::HandleObject obj, JS::HandleId id)
proxy_GetGeneric, \
proxy_GetProperty, \
proxy_GetElement, \
proxy_GetElementIfPresent, \
proxy_GetSpecial, \
proxy_SetGeneric, \
proxy_SetProperty, \
@ -3186,7 +3122,6 @@ const Class js::OuterWindowProxyObject::class_ = {
proxy_GetGeneric,
proxy_GetProperty,
proxy_GetElement,
proxy_GetElementIfPresent,
proxy_GetSpecial,
proxy_SetGeneric,
proxy_SetProperty,

View File

@ -162,8 +162,6 @@ class JS_FRIEND_API(BaseProxyHandler)
virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g);
virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp);
virtual void finalize(JSFreeOp *fop, JSObject *proxy);
virtual bool getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver,
uint32_t index, MutableHandleValue vp, bool *present);
virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop);
// These two hooks must be overridden, or not overridden, in tandem -- no
@ -262,8 +260,6 @@ class Proxy
static bool hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool *bp);
static bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id,
MutableHandleValue vp);
static bool getElementIfPresent(JSContext *cx, HandleObject proxy, HandleObject receiver,
uint32_t index, MutableHandleValue vp, bool *present);
static bool set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id,
bool strict, MutableHandleValue vp);
static bool keys(JSContext *cx, HandleObject proxy, AutoIdVector &props);

View File

@ -820,14 +820,6 @@ DeadObjectProxy::defaultValue(JSContext *cx, HandleObject obj, JSType hint, Muta
return false;
}
bool
DeadObjectProxy::getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver,
uint32_t index, MutableHandleValue vp, bool *present)
{
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_DEAD_OBJECT);
return false;
}
bool
DeadObjectProxy::getPrototypeOf(JSContext *cx, HandleObject proxy, MutableHandleObject protop)
{

View File

@ -204,9 +204,6 @@ class JS_FRIEND_API(DeadObjectProxy) : public BaseProxyHandler
virtual bool regexp_toShared(JSContext *cx, HandleObject proxy, RegExpGuard *g) MOZ_OVERRIDE;
virtual bool defaultValue(JSContext *cx, HandleObject obj, JSType hint,
MutableHandleValue vp) MOZ_OVERRIDE;
virtual bool getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver,
uint32_t index, MutableHandleValue vp,
bool *present) MOZ_OVERRIDE;
virtual bool getPrototypeOf(JSContext *cx, HandleObject proxy,
MutableHandleObject protop) MOZ_OVERRIDE;

View File

@ -557,7 +557,6 @@ const Class WithObject::class_ = {
with_GetGeneric,
with_GetProperty,
with_GetElement,
nullptr, /* getElementIfPresent */
with_GetSpecial,
with_SetGeneric,
with_SetProperty,

View File

@ -1037,16 +1037,6 @@ ArrayBufferObject::obj_getElement(JSContext *cx, HandleObject obj,
return baseops::GetElement(cx, delegate, receiver, index, vp);
}
bool
ArrayBufferObject::obj_getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver,
uint32_t index, MutableHandleValue vp, bool *present)
{
RootedObject delegate(cx, ArrayBufferDelegate(cx, obj));
if (!delegate)
return false;
return JSObject::getElementIfPresent(cx, delegate, receiver, index, vp, present);
}
bool
ArrayBufferObject::obj_getSpecial(JSContext *cx, HandleObject obj,
HandleObject receiver, HandleSpecialId sid,
@ -1494,27 +1484,6 @@ class TypedArrayObjectTemplate : public TypedArrayObject
return obj_getProperty(cx, obj, receiver, name, vp);
}
static bool
obj_getElementIfPresent(JSContext *cx, HandleObject tarray, HandleObject receiver, uint32_t index,
MutableHandleValue vp, bool *present)
{
// Fast-path the common case of index < length
if (index < tarray->as<TypedArrayObject>().length()) {
// this inline function is specialized for each type
copyIndexToValue(tarray, index, vp);
*present = true;
return true;
}
RootedObject proto(cx, tarray->getProto());
if (!proto) {
vp.setUndefined();
return true;
}
return JSObject::getElementIfPresent(cx, proto, receiver, index, vp, present);
}
static bool
setElementTail(JSContext *cx, HandleObject tarray, uint32_t index,
MutableHandleValue vp, bool strict)
@ -3480,7 +3449,6 @@ const Class ArrayBufferObject::class_ = {
ArrayBufferObject::obj_getGeneric,
ArrayBufferObject::obj_getProperty,
ArrayBufferObject::obj_getElement,
ArrayBufferObject::obj_getElementIfPresent,
ArrayBufferObject::obj_getSpecial,
ArrayBufferObject::obj_setGeneric,
ArrayBufferObject::obj_setProperty,
@ -3643,7 +3611,6 @@ IMPL_TYPED_ARRAY_COMBINED_UNWRAPPERS(Float64, double, double)
_typedArray##Object::obj_getGeneric, \
_typedArray##Object::obj_getProperty, \
_typedArray##Object::obj_getElement, \
_typedArray##Object::obj_getElementIfPresent, \
_typedArray##Object::obj_getSpecial, \
_typedArray##Object::obj_setGeneric, \
_typedArray##Object::obj_setProperty, \

View File

@ -107,8 +107,6 @@ class ArrayBufferObject : public JSObject
static bool obj_getElement(JSContext *cx, HandleObject obj, HandleObject receiver,
uint32_t index, MutableHandleValue vp);
static bool obj_getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver,
uint32_t index, MutableHandleValue vp, bool *present);
static bool obj_getSpecial(JSContext *cx, HandleObject obj, HandleObject receiver,
HandleSpecialId sid, MutableHandleValue vp);

View File

@ -720,7 +720,6 @@ const XPCWrappedNativeJSClass XPC_WN_NoHelper_JSClass = {
nullptr, // getGeneric
nullptr, // getProperty
nullptr, // getElement
nullptr, // getElementIfPresent
nullptr, // getSpecial
nullptr, // setGeneric
nullptr, // setProperty

View File

@ -982,7 +982,6 @@ XPC_WN_JSOp_ThisObject(JSContext *cx, JS::HandleObject obj);
nullptr, /* getGeneric */ \
nullptr, /* getProperty */ \
nullptr, /* getElement */ \
nullptr, /* getElementIfPresent */ \
nullptr, /* getSpecial */ \
nullptr, /* setGeneric */ \
nullptr, /* setProperty */ \
@ -1011,7 +1010,6 @@ XPC_WN_JSOp_ThisObject(JSContext *cx, JS::HandleObject obj);
nullptr, /* getGeneric */ \
nullptr, /* getProperty */ \
nullptr, /* getElement */ \
nullptr, /* getElementIfPresent */ \
nullptr, /* getSpecial */ \
nullptr, /* setGeneric */ \
nullptr, /* setProperty */ \