JS_CompileScript 编辑
Compiles a script for execution.
Syntax
// Added in SpiderMonkey 45
bool
JS_CompileScript(JSContext *cx,
const char *ascii, size_t length,
const JS::CompileOptions &options,
JS::MutableHandleScript script);
bool
JS_CompileUCScript(JSContext *cx,
const char16_t *chars, size_t length,
const JS::CompileOptions &options,
JS::MutableHandleScript script);
// Obsolete since JSAPI 39
bool
JS_CompileScript(JSContext *cx, JS::HandleObject obj,
const char *ascii, size_t length,
const JS::CompileOptions &options,
JS::MutableHandleScript script);
bool
JS_CompileUCScript(JSContext *cx, JS::HandleObject obj,
const char16_t *chars, size_t length,
const JS::CompileOptions &options,
JS::MutableHandleScript script);
Name | Type | Description |
---|---|---|
cx | JSContext * | Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
obj | JS::HandleObject | The global object, or NULL . If the JSOPTION_COMPILE_N_GO option is set in cx , the resulting script must be executed in this scope, and at most once. Obsolete since JSAPI 39 |
ascii or chars | const char * or const char16_t * | String containing the script to compile. |
length | size_t | The length, in characters, of source . |
options | JS::CompileOptions & | Compile options. |
script | JS::MutableHandleScript | Out parameter. On success, script receives the result script. |
Description
JS_CompileScript
compiles a script, source
, for execution. JS_CompileUCScript
is the Unicode version of the function.
The script is associated with a JS object. ascii
and chars
are the string containing the text of the script. length
indicates the size of the text version of the script in characters.
On success, JS_CompileScript
and JS_CompileUCScript
stores the newly compiled script to *script
and returns true
. Otherwise, they report an error, stores NULL
to *script
, and return false
.
See Also
- The JSAPI User Guide contains example code using compiled scripts.
- MXR ID Search for
JS_CompileScript
- MXR ID Search for
JS_CompileUCScript
JS::Evaluate
JS::CompileOffThread
JS::CompileFunction
JS_ExecuteScript
JS_DecompileScript
- bug 1143793 -- removed
obj
parameter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论