JavaScript-1.5 Reference

JS_SetProperty Function

Summary

Sets the current value of a property belonging to a specified object.

Syntax

JSBool JS_SetProperty(JSContext *cx, JSObject *obj,
    const char *name, jsval *vp);
NameTypeDescription
cxJSContext *Pointer to a JS context from which to derive runtime information.
objJSObject *Object to which the property to set belongs.
nameconst char *Name of the property to set.
vpjsval *Pointer to the value to set for the property.

Description

JS_SetProperty sets the current value of a property for a specified object. If the property does not exist, this function creates it, and inherits its attributes from a like-named property in the object's prototype chain. For properties it creates, JS_SetProperty sets the JSPROP_ENUMERATE attribute in the property's flags field; all other values for the property are undefined.

name is the property to set, and vp is a pointer to the new value to set for the property. On successfully setting a property to a new value, JS_SetProperty returns JS_TRUE. Otherwise it returns JS_FALSE.

If you attempt to set the value for a read-only property using JavaScript 1.2 or earlier, JS_SetProperty reports an error and returns JS_FALSE. For JavaScript 1.3 and greater, such an attempt is silently ignored.

If you attempt to set the value for a property that does not exist, and there is a like-named read-only property in the object's prototype chain, JS_SetProperty creates a new read-only property on the object, sets its value to JSVAL_VOID, and reports a read-only violation error.

See Also

Groups [ Function ]
Documents [ LXR ID Search ]
Entries [ JSPROP_ENUMERATE | JSVAL_VOID | JS_AliasProperty | JS_DefineProperty | JS_DefinePropertyWithTinyId | JS_DefineUCProperty | JS_DefineUCPropertyWithTinyID | JS_DeleteProperty | JS_DeleteProperty2 | JS_DeleteUCProperty2 | JS_GetProperty | JS_GetUCProperty | JS_LookupProperty | JS_PropertyStub | JS_SetUCProperty ]

This page was generated by APIDOC