JS_SetElement

Assign a value to a numeric property of an object.

Syntax

JSBool JS_SetElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp);
Name Type Description
cx JSContext * The context in which to set the element. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
obj JSObject * The object to modify, commonly an Array object.
index jsint Index number of the element to set.
vp jsval * In/out parameter. *vp is the value to assign to the element. JS_SetElement ordinarily leaves *vp unchanged, but a JSClass.addProperty hook or non-default setter may modify it.

Description

JS_SetElement assigns a value to a numeric property of an object. It behaves like the JavaScript expression obj[index] = v.

JS_SetElement first converts index to a jsid. Then it sets the specified property as though by calling JS_SetPropertyById(cx, obj, id, vp).

On success, JS_SetElement returns JS_TRUE and the value left in *vp is left unchanged unless an addProperty hook or setter modified it. On error or exception, JS_SetElement returns JS_FALSE and the value left in *vp is unspecified.

MXR ID Search for JS_SetElement

Document Tags and Contributors

Contributors to this page: MMondor, mauve, Dria, Jorend
Last updated by: Jorend,