JavaScript-1.5 Reference

JS_SetElement Function

Summary

Sets the current value of an element or numeric property belonging to a specified object.

Syntax

JSBool JS_SetElement(JSContext *cx, JSObject *obj, jsint index,
    jsval *vp);
NameTypeDescription
cxJSContext *Pointer to a JS context from which to derive runtime information.
objJSObject *Array object to which the element to set belongs.
indexjsintIndex number of the element to set.
vpjsval *Pointer to the value to set for the element.

Description

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

index is element number to set, and vp is a pointer to the new value to set for the element. On successfully setting an element to a new value, JS_SetElement returns JS_TRUE. Otherwise it returns JS_FALSE.

If you attempt to set the value for a read-only element using JavaScript 1.2 or earlier, JS_SetElement 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 an element that does not exist, and there is a like-named read-only element in the object's prototype chain, JS_SetElement creates a new read-only element 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_AliasElement | JS_DefineElement | JS_DeleteElement | JS_GetArrayLength | JS_GetElement | JS_IsArrayObject | JS_LookupElement | JS_NewArrayObject | JS_SetArrayLength ]

This page was generated by APIDOC