JS::CompileFunction 编辑
This article covers features introduced in SpiderMonkey 17
Create a JavaScript function from a text string.
Syntax
bool
JS::CompileFunction(JSContext *cx, JS::AutoObjectVector &scopeChain,
const JS::ReadOnlyCompileOptions &options,
const char *name, unsigned nargs, const char *const *argnames,
const char16_t *chars, size_t length, JS::MutableHandleFunction fun);
bool
JS::CompileFunction(JSContext *cx, JS::AutoObjectVector &scopeChain,
const JS::ReadOnlyCompileOptions &options,
const char *name, unsigned nargs, const char *const *argnames,
JS::SourceBufferHolder &srcBuf, JS::MutableHandleFunction fun);
bool
JS::CompileFunction(JSContext *cx, JS::AutoObjectVector &scopeChain,
const JS::ReadOnlyCompileOptions &options,
const char *name, unsigned nargs, const char *const *argnames,
const char *bytes, size_t length, JS::MutableHandleFunction fun);
Name | Type | Description |
---|---|---|
cx | JSContext * | The context in which to compile the function. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
scopeChain | JS::AutoObjectVector & | The scope in which to compile the function. |
options | JS::ReadOnlyCompileOptions & | Compile options. |
name | const char * | Name to assign the newly compiled function. |
nargs | unsigned | Number of arguments to pass to the function. |
argnames | const char *const * | Names to assign to the arguments passed to the function. |
chars | const char16_t * | String containing the body of the function to compile. |
bytes | const char * | String containing the body of the function to compile. |
length | size_t | The length, in characters, of body . |
srcBuf | JS::SourceBufferHolder & | Source buffer containing the script function compile. |
fun | JS::MutableHandleFunction | Out parameter. On success, fun receives the result function. |
Description
JS::CompileFunction
compiles a function from a text string chars
, bytes
, or srcBuf
.
name
is the name to assign to the newly created function. nargs
is the number of arguments the function takes, and argnames
is a pointer to the first element of an array of names to assign each argument. The number of argument names should match the number of arguments specified in nargs
.
chars
, bytes
, or srcBuf
is a string containing the source code of the function. length
is the length of the source code in characters.
On success, JS::CompileFunction
stores an function object representing the newly compiled function into fun
and and returns true
. Otherwise, it returns false
and the value left in fun
is undefined.
See Also
- The JSAPI User Guide contains example code using compiled scripts.
- MXR ID Search for
JS::CompileFunction
JS::Evaluate
JS::Compile
JS::CompileOffThread
JS_ExecuteScript
JS_DecompileScript
- bug 771705
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论