This article covers features introduced in SpiderMonkey 31
Root an internal fixed-size array of JS::Value
s.
Syntax
JS::AutoValueArray<N> vp(cx);
Name | Type | Description |
---|---|---|
cx |
JSContext * |
The context in which to add the root. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
N |
size_t |
Size of a JS::Value array. |
Description
JS::AutoValueArray<N>
holds a rooted array of JS::Value
. This is typically used for local variables being passed to function which requires JS::HandleValueArray
or a pointer to JS::Value
array.
Examples
Pass to function as a pointer to JS::Value
.
bool
someFunction1(JSContext *cx, unsigned argc, const JS::Value *argv) {
/* ... */
}
JS::AutoValueArray<2> args(cx);
/* ... Initialize args[0] and args[1] here ... */
someFunction1(cx, 2, args.begin());
Pass to function as JS::HandleValueArray
.
bool
someFunction2(JSContext *cx, const JS::HandleValueArray &args) {
/* ... */
}
JS::AutoValueArray<2> args(cx);
/* ... Initialize args[0] and args[1] here ... */
someFunction2(cx, args);