pub struct Property {
pub value: Option<Value>,
pub getter: Option<Value>,
pub setter: Option<Value>,
pub writable: bool,
pub enumerable: bool,
pub configurable: bool,
}Expand description
A property of an object.
Fields§
§value: Option<Value>The value of a data property.
getter: Option<Value>The getter of an accessor property.
setter: Option<Value>The setter of an accessor property.
writable: boolWhether the value can be replaced.
enumerable: boolWhether for/Object.keys sees the property.
configurable: boolWhether the property can be deleted or redefined.
Implementations§
Source§impl Property
impl Property
Sourcepub fn data(value: Value) -> Property
pub fn data(value: Value) -> Property
A writable, enumerable, configurable data property.
This is what a plain assignment or an object literal creates, and the
attributes only differ for built-ins and Object.defineProperty.
Sourcepub fn with_attributes(
value: Value,
writable: bool,
enumerable: bool,
) -> Property
pub fn with_attributes( value: Value, writable: bool, enumerable: bool, ) -> Property
A data property with explicit attributes.
configurable is derived from writable, because that derivation is right for the
case this is overwhelmingly used for: a built-in method or constructor, which the
spec gives {writable: true, enumerable: false, configurable: true}.
It is not right for the two other shapes the spec uses on functions, and both were
wrong here for a long time — name/length are {writable: false, enumerable: false, configurable: true}, and a function’s prototype is {writable: true, enumerable: false, configurable: false}. Use Property::name_or_length and
Property::prototype_of for those rather than spelling them out, so that the two
exceptions to the rule stay in one place.
Sourcepub fn name_or_length(value: Value) -> Property
pub fn name_or_length(value: Value) -> Property
A name or length property: writable and enumerable are false, configurable true.
Every function has both, and the spec makes them configurable so that a definition
can replace them (Object.defineProperty(f, "length", {value: 0}), and
Function.prototype.bind renaming its result). With them non-configurable, those
definitions throw and about five hundred conformance tests fail.
Sourcepub fn prototype_of(value: Value, writable: bool) -> Property
pub fn prototype_of(value: Value, writable: bool) -> Property
A function’s prototype: not configurable, and writable only for user functions.
A built-in constructor’s prototype is read-only — assigning to Object.prototype
must not stick — while a user function’s is writable, since that is how
Ctor.prototype.method = f sets up inheritance. Neither is configurable, so
delete Ctor.prototype fails in both cases.
Sourcepub fn accessor_with(
getter: Option<Value>,
setter: Option<Value>,
enumerable: bool,
) -> Property
pub fn accessor_with( getter: Option<Value>, setter: Option<Value>, enumerable: bool, ) -> Property
An accessor property.
An accessor property with explicit enumerable/configurable flags, which is
what Symbol.prototype.description needs: it is enumerable: false in the spec.
Sourcepub fn accessor(getter: Option<Value>, setter: Option<Value>) -> Property
pub fn accessor(getter: Option<Value>, setter: Option<Value>) -> Property
An accessor property with the default enumerable/configurable flags.
Sourcepub fn is_accessor(&self) -> bool
pub fn is_accessor(&self) -> bool
Whether this is an accessor rather than a data property.