Fix for bug 852094 (Support Unforgeable on proxy-based DOM bindings) - add a JS_DefineOwnProperty API that takes a JSPropertyDescriptor. r=Waldo.

--HG--
extra : rebase_source : 1866bae0a324ba952548c375e0c8cc031d8b0954
This commit is contained in:
Peter Van der Beken 2013-03-27 18:15:38 +01:00
Родитель 5ee0bbf184
Коммит 2d1456add4
4 изменённых файлов: 43 добавлений и 0 удалений

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

@ -1037,3 +1037,20 @@ js::AutoCTypesActivityCallback::AutoCTypesActivityCallback(JSContext *cx,
if (callback)
callback(cx, beginType);
}
JS_FRIEND_API(JSBool)
js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg,
const js::PropertyDescriptor& descriptor, JSBool *bp)
{
RootedObject obj(cx, objArg);
RootedId id(cx, idArg);
JS_ASSERT(cx->runtime->heapState == js::Idle);
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj, id, descriptor.value);
if (descriptor.attrs & JSPROP_GETTER)
assertSameCompartment(cx, CastAsObjectJsval(descriptor.getter));
if (descriptor.attrs & JSPROP_SETTER)
assertSameCompartment(cx, CastAsObjectJsval(descriptor.setter));
return js_DefineOwnProperty(cx, HandleObject(obj), id, descriptor, bp);
}

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

@ -1440,4 +1440,8 @@ inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id) {};
} /* namespace js */
extern JS_FRIEND_API(JSBool)
js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg,
const js::PropertyDescriptor& descriptor, JSBool *bp);
#endif /* jsfriendapi_h___ */

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

@ -992,6 +992,24 @@ js_DefineOwnProperty(JSContext *cx, HandleObject obj, HandleId id, const Value &
return true;
}
JSBool
js_DefineOwnProperty(JSContext *cx, HandleObject obj, HandleId id,
const PropertyDescriptor &descriptor, JSBool *bp)
{
AutoPropDescArrayRooter descs(cx);
PropDesc *desc = descs.append();
if (!desc)
return false;
desc->initFromPropertyDescriptor(descriptor);
bool rval;
if (!DefineProperty(cx, obj, id, *desc, true, &rval))
return false;
*bp = !!rval;
return true;
}
bool
js::ReadPropertyDescriptors(JSContext *cx, HandleObject props, bool checkAccessors,

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

@ -1156,6 +1156,10 @@ extern JSBool
js_DefineOwnProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
const JS::Value &descriptor, JSBool *bp);
extern JSBool
js_DefineOwnProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
const js::PropertyDescriptor &descriptor, JSBool *bp);
namespace js {
/*