JS_PushArguments 编辑
Obsolete since JavaScript 1.8.5
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
Convert any number of arguments to jsval
s and store the resulting jsval
s in an array.
Syntax
jsval *
JS_PushArguments(JSContext *cx, void **markp, const char *format, ...);
jsval *
JS_PushArgumentsVA(JSContext *cx, void **markp, const char *format, va_list ap);
Name | Type | Description |
---|---|---|
cx | JSContext * | The context in which to perform any necessary conversions.
JS_THREADSAFE build, the caller must be in a request on this JSContext . |
markp | void ** | Out parameter. On success, *markp receives the internally allocated stack mark which should be passed to JS_PopArguments . |
format | const char * | Null-terminated string holding a list of format types to convert the following arguments to. |
... | various | (in JS_PushArguments ) A variable number of arguments to be converted to jsval s. There must be one argument for each argument described in format . |
ap | va_list | (in JS_PushArgumentsVA ) The list of arguments to be converted to jsval s. There must be one argument for each argument described in format . The type va_list is a standard feature of the C programming language. It is defined in <stdarg.h> . |
Description
JS_PushArguments
provides a convenient way to translate a series of native C/C++ values to jsval
s with a single function call.
cx
is the context for the call. markp
points to a void *
to hold the internally allocated stack frame pointer to pass back to JS_PopArguments
.
format
is a sequential character array, where each element of the array indicates the JS type into which to convert the next C/C++ argument. format
can contain one or more instances of the following characters, as appropriate:
Character | Argument type |
---|---|
b | JSBool |
c | uint16 (16-bit, unsigned integer) |
i | int32 (32-bit, ECMA-compliant signed integer) |
u | uint32 (32-bit, ECMA-compliant, unsigned integer) |
j | int32 (32-bit, signed integer) |
d | jsdouble |
I | jsdouble (converted to an integer value) |
s | char * (C string) |
S | JSString * (Unicode string) |
W | jschar * (Unicode null-terminated string) |
o | JSObject * |
f | JSFunction * |
* | None. Any asterisks (* ) in format are ignored. |
This function also takes in consideration any additional custom types defined in cx
using JS_AddArgumentFormatter
.
For example, if format
is "bIob"
, then there must be four arguments after format
. Their types must be JSBool
, jsdouble
, JSObject *
, and JSBool
. If successful, JS_PushArguments
would return a pointer to the first element of an array of four jsval
s: a boolean, a number, an object (or null), and a boolean.
On success, JS_PushArguments
fills in the supplied markp
pointer and returns a pointer to the first element of an array of jsval
which are automatically rooted as necessary (protected from the GC temporarily). The application must call JS_PopArguments
using the supplied markp
stack pointer when done with this stack frame, to free the memory and unroot the jsval
s.
On error or exception, JS_PushArguments
returns NULL
.
To perform the opposite conversion, converting an array of jsval
s to various native C types, use JS_ConvertArguments
.
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论