JS_NewArrayObject |
Function |
|
Summary
Creates a new array object.
|
Syntax
JSObject * JS_NewArrayObject(JSContext *cx, jsint length,
jsval *vector);
Name | Type | Description |
cx | JSContext * | Pointer to a JS context from which to derive runtime information.
|
length | jsint | Number of elements to include in the array.
|
vector | jsval * | Pointer to the initial values for the array's elements.
|
|
Description
JS_NewArrayObject creates a new array object in the JSRuntime of the specified JSContext , cx . If array creation is successful, JS_NewArrayObject initializes each element identified by index i from 0 to length - 1 to have the value vector[i] , and then returns a pointer to the new object. Otherwise JS_NewArrayObject returns NULL .length specifies the number of elements in the array. If length is 0 , JS_NewArrayObject creates an array object of length 0 and ignores vector .
|
Notes
It is often better to call JS_NewArrayObject(cx, 0, NULL) , store the returned object in a GC root, and then populate its elements with JS_SetElement or JS_DefineElement . This avoids unrooted jsval s in vector from being subject to garbage collection until the new object has been populated.
|
See Also
|