Bug 698495 part 5. Implement getElementIfPresent on nodelist proxies. r=peterv

This commit is contained in:
Boris Zbarsky 2011-11-04 12:25:18 -04:00
Родитель b1d3ff3b30
Коммит fce5566a61
2 изменённых файлов: 48 добавлений и 0 удалений

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

@ -1042,6 +1042,52 @@ ListBase<LC>::get(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, V
return true;
}
template<class LC>
bool
ListBase<LC>::getElementIfPresent(JSContext *cx, JSObject *proxy, JSObject *receiver,
uint32 index, Value *vp, bool *present)
{
if (hasIndexGetter) {
IndexGetterType result;
*present = getItemAt(getListObject(proxy), index, result);
if (*present)
return Wrap(cx, proxy, result, vp);
vp->setUndefined();
return true;
}
jsid id;
if (!JS_IndexToId(cx, index, &id))
return false;
JSObject *expando = getExpandoObject(proxy);
if (expando) {
JSBool isPresent;
if (!JS_GetElementIfPresent(cx, expando, index, expando, vp, &isPresent))
return false;
if (isPresent) {
*present = true;
return true;
}
}
// No need to worry about name getters here, so just check the proto.
JSObject *proto = js::GetObjectProto(proxy);
if (proto) {
JSBool 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;
}
template<class LC>
bool
ListBase<LC>::set(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, bool strict,

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

@ -225,6 +225,8 @@ public:
bool has(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
bool hasOwn(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
bool get(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, js::Value *vp);
bool getElementIfPresent(JSContext *cx, JSObject *proxy, JSObject *receiver,
uint32 index, js::Value *vp, bool *present);
bool set(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, bool strict,
js::Value *vp);
bool keys(JSContext *cx, JSObject *proxy, js::AutoIdVector &props);