Property attributes

Any object property can have zero or more property attributes set.

Some property attributes are defined in the ECMAScript standard, in ECMA 262-3 ยง8.6.1. SpiderMonkey additionally defines several non-standard property attributes.

The JSAPI expresses property attributes as a value of type unsigned, the bitwise OR of zero or more of the JSPROP flags described below.

An application can set property attributes when creating a property. See JS_DefineProperty, JS_FS, and JS_FN

Flag Description
JSPROP_ENUMERATE

The property is visible to JavaScript for...in and for each ... in loops, as well as to JS_Enumerate.

This is the inverse of the ECMA standard DontEnum attribute.

MXR ID Search for JSPROP_ENUMERATE

JSPROP_READONLY

The property's value cannot be set. In JavaScript 1.2 and lower, it is an error to attempt to assign a value to a read-only property. In JavaScript 1.3 and higher, as in ECMAScript, attempts to set a value on a read-only property are ignored.

This is the ECMA standard ReadOnly attribute.

MXR ID Search for JSPROP_READONLY

JSPROP_PERMANENT

The property cannot be deleted. In JavaScript 1.2 and lower, it is an error to attempt to delete a permanent property. In JavaScript 1.3 and higher, as in ECMAScript, such attempts are ignored.

This is the ECMA standard DontDelete attribute.

The JavaScript language does not provide any way for a script to delete a permanent property.

MXR ID Search for JSPROP_PERMANENT

JSPROP_PROPOP_ACCESSORS

Passed to JS_Define(UC)Property* and JS_DefineElement if getters/setters are JSPropertyOp/JSStrictPropertyOp Added in SpiderMonkey 38.

MXR ID Search for JSPROP_PROPOP_ACCESSORS

JSPROP_GETTER

The property's getter is a JavaScript Function, not a C/C++ function. See JS_DefineProperty for details.

MXR ID Search for JSPROP_GETTER

JSPROP_SETTER

The property's setter is a JavaScript Function, not a C/C++ function. See JS_DefineProperty for details.

MXR ID Search for JSPROP_SETTER

JSPROP_SHARED

The property is shared. This is usually the right thing for properties that have getters or setters. This has three effects:

  1. The JavaScript engine does not set aside any memory for the property's value. The value is determined entirely by the getter. (The property has no stored value.)
  2. Assignment via the prototype chain is affected. Assigning to obj.x, where obj inherits a non-shared property from its prototype, creates a new own data property on obj; the prototype's .x is not shared with its children. If the inherited property is shared, the setter is called instead.
  3. If the property is also JSPROP_PERMANENT, then certain aspects of inheriting the property via the prototype chain are affected. Do not depend on this. See bug 575997.

MXR ID Search for JSPROP_SHARED

JSPROP_INDEX

The property's id is represented internally as an integer, not a string. Obsolete since JSAPI 39

This flag has an additional special meaning when used with JS_DefineProperty, JS_FS, and other APIs that define properties: it means that the name parameter is actually an integer unsafely cast to a pointer type, not a string.

MXR ID Search for JSPROP_INDEX

JSPROP_DEFINE_LATE

Don't define property when initially creating the constructor. Some objects like Function/Object have self-hosted functions that can only be defined after the initialization is already finished. Added in SpiderMonkey 38

MXR ID Search for JSPROP_DEFINE_LATE

JSFUN_STUB_GSOPS

Use JS_PropertyStub getter/setter instead of defaulting to class gsops for property holding function. Added in SpiderMonkey 17

MXR ID Search for JSFUN_STUB_GSOPS

JSFUN_CONSTRUCTOR

Native that can be called as a constructor. Added in SpiderMonkey 17

MXR ID Search for JSFUN_CONSTRUCTOR

JSPROP_REDEFINE_NONCONFIGURABLE

If set, will allow redefining a non-configurable property, but only on a non-DOM global. This is a temporary hack that will need to go away in bug 1105518. Added in SpiderMonkey 38

MXR ID Search for JSPROP_REDEFINE_NONCONFIGURABLE

JSPROP_RESOLVING

Resolve hooks and enumerate hooks must pass this flag when calling JS_Define* APIs to reify lazily-defined properties.

JSPROP_RESOLVING is used only with property-defining APIs. It tells the engine to skip the resolve hook when performing the lookup at the beginning of property definition. This keeps the resolve hook from accidentally triggering itself: unchecked recursion.

For enumerate hooks, triggering the resolve hook would be merely silly, not fatal, except in some cases involving non-configurable properties.

Added in SpiderMonkey 45

MXR ID Search for JSPROP_RESOLVING

JSPROP_IGNORE_ENUMERATE

Ignore the value in JSPROP_ENUMERATE. This flag only valid when defining over an existing property. Added in SpiderMonkey 38

MXR ID Search for JSPROP_IGNORE_ENUMERATE

JSPROP_IGNORE_READONLY

Ignore the value in JSPROP_READONLY. This flag only valid when defining over an existing property. Added in SpiderMonkey 38

MXR ID Search for JSPROP_IGNORE_READONLY

JSPROP_IGNORE_PERMANENT

Ignore the value in JSPROP_PERMANENT. This flag only valid when defining over an existing property. Added in SpiderMonkey 38

MXR ID Search for JSPROP_IGNORE_PERMANENT

JSPROP_IGNORE_VALUE

Ignore the JS::Value in the descriptor. Nothing was specified when passed to Object.defineProperty from script. Added in SpiderMonkey 38

MXR ID Search for JSPROP_IGNORE_VALUE

See Also