Bug 965898 - Generalize FilterSetter to work on all the relevant fields of JSPropertyDescriptor. r=gabor

This commit is contained in:
Bobby Holley 2014-07-30 12:23:03 -07:00
Родитель 26e1c71573
Коммит a348ab6fd4
1 изменённых файлов: 25 добавлений и 7 удалений

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

@ -45,14 +45,32 @@ Filter(JSContext *cx, HandleObject wrapper, AutoIdVector &props)
template <typename Policy>
static bool
FilterSetter(JSContext *cx, JSObject *wrapper, jsid id, JS::MutableHandle<JSPropertyDescriptor> desc)
FilterPropertyDescriptor(JSContext *cx, JSObject *wrapper, HandleId id, JS::MutableHandle<JSPropertyDescriptor> desc)
{
bool setAllowed = Policy::check(cx, wrapper, id, Wrapper::SET);
if (!setAllowed) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
bool getAllowed = Policy::check(cx, wrapper, id, Wrapper::GET);
if (JS_IsExceptionPending(cx))
return false;
bool setAllowed = Policy::check(cx, wrapper, id, Wrapper::SET);
if (JS_IsExceptionPending(cx))
return false;
MOZ_ASSERT(getAllowed || setAllowed,
"Filtering policy should not allow GET_PROPERTY_DESCRIPTOR in this case");
if (!desc.hasGetterOrSetter()) {
// Handle value properties.
if (!getAllowed)
desc.value().setUndefined();
} else {
// Handle accessor properties.
MOZ_ASSERT(desc.value().isUndefined());
if (!getAllowed)
desc.setGetter(nullptr);
if (!setAllowed)
desc.setSetter(nullptr);
}
return true;
}
@ -65,7 +83,7 @@ FilteringWrapper<Base, Policy>::getPropertyDescriptor(JSContext *cx, HandleObjec
assertEnteredPolicy(cx, wrapper, id, BaseProxyHandler::GET | BaseProxyHandler::SET);
if (!Base::getPropertyDescriptor(cx, wrapper, id, desc))
return false;
return FilterSetter<Policy>(cx, wrapper, id, desc);
return FilterPropertyDescriptor<Policy>(cx, wrapper, id, desc);
}
template <typename Base, typename Policy>
@ -77,7 +95,7 @@ FilteringWrapper<Base, Policy>::getOwnPropertyDescriptor(JSContext *cx, HandleOb
assertEnteredPolicy(cx, wrapper, id, BaseProxyHandler::GET | BaseProxyHandler::SET);
if (!Base::getOwnPropertyDescriptor(cx, wrapper, id, desc))
return false;
return FilterSetter<Policy>(cx, wrapper, id, desc);
return FilterPropertyDescriptor<Policy>(cx, wrapper, id, desc);
}
template <typename Base, typename Policy>