Assign a value to an object property.
JSBool JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp); JSBool JS_SetUCProperty(JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, jsval *vp);
| Name | Type | Description |
|---|---|---|
cx |
JSContext * |
Pointer to a JS context from which to derive runtime information.
Requires request. (In a JS_THREADSAFE build, the caller must be in a request on this JSContext.)
|
obj |
JSObject * |
Object to which the property to set belongs. |
name |
const char * or const jschar * |
Name of the property to set. |
namelen |
size_t |
(only in JS_SetUCProperty) The length of name in characters; or -1 to indicate that name is null-terminated. |
vp |
jsval * |
In/out parameter. (???) Pointer to the value to set for the property. |
JS_SetProperty assigns the value *vp to the property name of the object obj. JS_SetUCProperty is the Unicode version of the function.
vp points to a variable containing the new value to assign to the property.
If obj does not already have a name property of its own, 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. (This is unclear: is the new property enumerable even if the like-named prototype property was DontEnum?)
On success, 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.
Page last modified 20:13, 21 Aug 2008 by Jorend