Mozilla.com

  1. MDC
  2. Main Page
  3. JS_GetPropertyAttributes
Redirected from En/JSPROP GETTER

JS_GetPropertyAttributes

Get the attributes of a specified property.

Syntax

JSBool JS_GetPropertyAttributes(JSContext *cx, JSObject *obj,
    const char *name, uintN *attrsp, JSBool *foundp);

JSBool JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj,
    const jschar *name, size_t namelen,
    uintN *attrsp, JSBool *foundp);
Name Type Description
cx JSContext * The context in which to look up property attributes. Requires request. (In a JS_THREADSAFE build, the caller must be in a request on this JSContext.)
obj JSObject * The object that has the property to be queried.
name const char * or const jschar * Name of the property from which to retrieve attributes.
namelen size_t (only in JS_GetUCPropertyAttributes) The length of name in characters; or (size_t) -1 to indicate that name is null-terminated.
attrsp uintN * Out parameter. If the specified property is found on obj, *attrsp receives its attributes.
foundp JSBool * Out parameter. If no error occurs, *foundp receives JS_TRUE if the specified property is found and JS_FALSE if it is not found. If an error occurs, the value left in *foundp is undefined.

Description

JS_GetPropertyAttributes retrieves the property attributes of the property with the given name on a given object, obj. JS_GetUCPropertyAttributes is the Unicode version of the function.

cx is the context. obj and name specify the object and property to examine. attrsp and foundp are the out parameters.

If an error occurs, the return value is JS_FALSE, and the values left in *attrsp and *foundp are undefined.

If obj does not have the specified property, or if it inherits it from some other object (on its prototype chain, for example), then *foundp is set to JS_FALSE. The value left in *attrsp is undefined. The return value is JS_TRUE (to indicate that no error occurred).

If the property exists and belongs to obj, then *foundp is set to JS_TRUE, *attrsp is set to the logical OR of zero or more property attribute flags (described below), and the function returns JS_TRUE.

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 uintN, the bitwise OR of zero or more of the JSPROP flags described below.

Flag Description

JSPROP_ENUMERATE

The property is visible to JavaScript forin and for eachin loops, as well as to JS_Enumerate.

This is the inverse of the ECMA standard DontEnum attribute.

LXR 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.

LXR 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. C/C++ code can do this by making the property non-permanent, using JS_SetPropertyAttributes, before deleting it.

LXR ID Search for JSPROP_PERMANENT

JSPROP_EXPORTED

The property can be imported by other scripts or objects, typically to borrow security privileges. (???)

LXR ID Search for JSPROP_EXPORTED

JSPROP_GETTER

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

LXR ID Search for JSPROP_GETTER

JSPROP_SETTER

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

LXR ID Search for JSPROP_SETTER

JSPROP_SHARED

The property is shared. The JavaScript engine does not allocate memory for the property's stored value. This attribute is appropriate for custom properties that are implemented as fields of a native C/C++ data structure or as C++ Get/Set method pairs. In such cases, the stored value slot is redundant at best and could entrain garbage.

Implementation note: A property with both JSPROP_SHARED and JSPROP_PERMANENT triggers a SpiderMonkey optimization: the property is not physically copied to an object that inherits it, as it normally would be in certain cases. The optimization is almost completely transparent, but JS_AlreadyHasOwnProperty can expose it.

LXR ID Search for JSPROP_SHARED

JSPROP_INDEX

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

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.

LXR ID Search for JSPROP_INDEX

An application can set property attributes when creating a property. See JS_DefineProperty, JS_FS, and JS_FN. To modify the attributes of an existing property, use JS_SetPropertyAttributes.

LXR ID Search for JS_GetPropertyAttributes
LXR ID Search for JS_GetUCPropertyAttributes

Page last modified 20:10, 21 Aug 2008 by Jorend

Files (0)