Get the attributes of a specified property.
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. |
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.
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 |
|---|---|
|
|
The property is visible to JavaScript This is the inverse of the ECMA standard DontEnum attribute. |
|
|
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. |
|
|
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 |
|
|
The property can be imported by other scripts or objects, typically to borrow security privileges. (???) |
|
|
The property's getter is a JavaScript |
|
|
The property's setter is a JavaScript |
|
|
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++ Implementation note: A property with both |
|
|
The property's id is represented internally as an integer, not a string. This flag has an additional special meaning when used with |
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