Bug 1148750, part 7 - Fill in configurable and enumerable. r=efaust.

This changes MutableHandle<PropertyDescriptor>::setEnumerable() to take a boolean argument, and makes it unconditionally clear JSPROP_IGNORE_ENUMERATE, as a convenience. A similar setConfigurable() method is also added.
This commit is contained in:
Jason Orendorff 2015-04-09 14:59:39 -05:00
parent 2c94987b4d
commit 259f08b290
2 changed files with 15 additions and 2 deletions

View File

@ -2701,7 +2701,14 @@ class MutablePropertyDescriptorOperations : public PropertyDescriptorOperations<
value().set(v);
}
void setEnumerable() { desc()->attrs |= JSPROP_ENUMERATE; }
void setConfigurable(bool configurable) {
setAttributes((desc()->attrs & ~(JSPROP_IGNORE_PERMANENT | JSPROP_PERMANENT)) |
(configurable ? 0 : JSPROP_PERMANENT));
}
void setEnumerable(bool enumerable) {
setAttributes((desc()->attrs & ~(JSPROP_IGNORE_ENUMERATE | JSPROP_ENUMERATE)) |
(enumerable ? JSPROP_ENUMERATE : 0));
}
void setAttributes(unsigned attrs) { desc()->attrs = attrs; }
void setGetter(JSGetterOp op) {

View File

@ -1190,7 +1190,7 @@ CheckAccessorRedefinition(ExclusiveContext* cx, HandleObject obj, HandleShape sh
}
static bool
AddOrChangeProperty(ExclusiveContext *cx, HandleNativeObject obj, HandleId id,
AddOrChangeProperty(ExclusiveContext* cx, HandleNativeObject obj, HandleId id,
Handle<PropertyDescriptor> desc)
{
desc.assertComplete();
@ -1370,6 +1370,12 @@ js::NativeDefineProperty(ExclusiveContext* cx, HandleNativeObject obj, HandleId
return result.fail(JSMSG_CANT_REDEFINE_PROP);
}
// Fill in desc.[[Configurable]] and desc.[[Enumerable]] if missing.
if (!desc.hasConfigurable())
desc.setConfigurable(IsConfigurable(shapeAttrs));
if (!desc.hasEnumerable())
desc.setEnumerable(IsEnumerable(shapeAttrs));
// If defining a getter or setter, we must check for its counterpart and
// update the attributes and property ops. A getter or setter is really
// only half of a property.