JavaScript-1.5 Reference

JS_NewArrayObject Function

Summary

Creates a new array object.

Syntax

JSObject * JS_NewArrayObject(JSContext *cx, jsint length,
    jsval *vector);
NameTypeDescription
cxJSContext *Pointer to a JS context from which to derive runtime information.
lengthjsintNumber of elements to include in the array.
vectorjsval *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 jsvals in vector from being subject to garbage collection until the new object has been populated.

See Also

Groups [ Function ]
Documents [ LXR ID Search ]
Entries [ JS_AliasElement | JS_DefineElement | JS_DeleteElement | JS_GetArrayLength | JS_GetElement | JS_IsArrayObject | JS_LookupElement | JS_SetArrayLength | JS_SetElement ]

This page was generated by APIDOC