Bug 1107443 part 3. Stop defining non-configurable properties on the window in xpconnect sandbox code. r=peterv,jorendorff

This commit is contained in:
Boris Zbarsky 2015-01-23 09:54:15 -05:00
Родитель cbb271e250
Коммит 3c92a4bdd7
3 изменённых файлов: 19 добавлений и 3 удалений

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

@ -224,10 +224,19 @@ JS_CopyPropertiesFrom(JSContext *cx, JS::HandleObject target, JS::HandleObject o
* property of the given name exists on |obj|. * property of the given name exists on |obj|.
* *
* On entry, |cx| must be same-compartment with |obj|. * On entry, |cx| must be same-compartment with |obj|.
*
* The copyBehavior argument controls what happens with
* non-configurable properties.
*/ */
typedef enum {
MakeNonConfigurableIntoConfigurable,
CopyNonConfigurableAsIs
} PropertyCopyBehavior;
extern JS_FRIEND_API(bool) extern JS_FRIEND_API(bool)
JS_CopyPropertyFrom(JSContext *cx, JS::HandleId id, JS::HandleObject target, JS_CopyPropertyFrom(JSContext *cx, JS::HandleId id, JS::HandleObject target,
JS::HandleObject obj); JS::HandleObject obj,
PropertyCopyBehavior copyBehavior = CopyNonConfigurableAsIs);
extern JS_FRIEND_API(bool) extern JS_FRIEND_API(bool)
JS_WrapPropertyDescriptor(JSContext *cx, JS::MutableHandle<JSPropertyDescriptor> desc); JS_WrapPropertyDescriptor(JSContext *cx, JS::MutableHandle<JSPropertyDescriptor> desc);

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

@ -1639,7 +1639,8 @@ JSObject::nonNativeSetElement(JSContext *cx, HandleObject obj, HandleObject rece
JS_FRIEND_API(bool) JS_FRIEND_API(bool)
JS_CopyPropertyFrom(JSContext *cx, HandleId id, HandleObject target, JS_CopyPropertyFrom(JSContext *cx, HandleId id, HandleObject target,
HandleObject obj) HandleObject obj,
PropertyCopyBehavior copyBehavior)
{ {
// |obj| and |cx| are generally not same-compartment with |target| here. // |obj| and |cx| are generally not same-compartment with |target| here.
assertSameCompartment(cx, obj, id); assertSameCompartment(cx, obj, id);
@ -1655,6 +1656,11 @@ JS_CopyPropertyFrom(JSContext *cx, HandleId id, HandleObject target,
if (desc.setter() && !desc.hasSetterObject()) if (desc.setter() && !desc.hasSetterObject())
return true; return true;
if (copyBehavior == MakeNonConfigurableIntoConfigurable) {
// Mask off the JSPROP_PERMANENT bit.
desc.attributesRef() &= ~JSPROP_PERMANENT;
}
JSAutoCompartment ac(cx, target); JSAutoCompartment ac(cx, target);
RootedId wrappedId(cx, id); RootedId wrappedId(cx, id);
if (!cx->compartment()->wrap(cx, &desc)) if (!cx->compartment()->wrap(cx, &desc))

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

@ -454,7 +454,8 @@ sandbox_addProperty(JSContext *cx, HandleObject obj, HandleId id, MutableHandleV
if (!JS_SetPropertyById(cx, proto, id, vp)) if (!JS_SetPropertyById(cx, proto, id, vp))
return false; return false;
} else { } else {
if (!JS_CopyPropertyFrom(cx, id, unwrappedProto, obj)) if (!JS_CopyPropertyFrom(cx, id, unwrappedProto, obj,
MakeNonConfigurableIntoConfigurable))
return false; return false;
} }