Obsolete since JSAPI 26
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Set the attributes for a specified property.

Syntax

JSBool
JS_SetPropertyAttributes(JSContext *cx, JSObject *obj,
    const char *name, unsigned int attrs, JSBool *foundp);

JSBool
JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj,
    const jschar *name, size_t namelen, unsigned int attrs,
    JSBool *foundp);
Name Type Description
cx JSContext * The context in which to set the property attributes. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
obj JSObject * Object for which to set property attributes.
name const char * or const jschar * Name of the property for which to set attributes.
namelen size_t (in JS_SetUCPropertyAttributes only) The length of name, in characters.
attrs unsigned int Attribute values to set.
foundp JSBool * Out parameter. Flag indicating whether or not the specified property was located.

Description

JS_SetPropertyAttributes sets the attributes for a specified property, name of an object obj. JS_SetUCPropertyAttributes is the Unicode version of the function.

attrs is an unsigned integer containing the attribute value to set. It is the bitwise OR of zero or more of the following values:

Flag Purpose
JSPROP_ENUMERATE Property is visible in for and in loops.
JSPROP_READONLY Property is read only.
JSPROP_PERMANENT Property cannot be deleted.
JSPROP_EXPORTED Property can be imported by other objects.
JSPROP_INDEX Property is actually an index into an array of properties, and is cast to a const char *.

If JS_SetPropertyAttributes cannot locate an object with the specified property, it returns JS_FALSE, and the value left in *foundp is undefined.

If the specified property or the specified object does not exist, foundp is set to JS_FALSE. Then, if the property exists, but is associated with a different object, JS_SetPropertyAttributes returns JS_TRUE. Otherwise, it sets foundp to JS_TRUE, and attempts to set the attributes as specified. If the attributes can be set, JS_SetPropertyAttributes returns JS_TRUE. If not, it returns JS_FALSE.

To get the attributes of a property, use JS_GetPropertyAttributes.