JS::Compile 编辑

This article covers features introduced in SpiderMonkey 17

Compile a script for execution.

Syntax

// Added in SpiderMonkey 45

bool
JS::Compile(JSContext *cx,
            const JS::ReadOnlyCompileOptions &options,
            JS::SourceBufferHolder &srcBuf, JS::MutableHandleScript script);

bool
JS::Compile(JSContext *cx,
            const JS::ReadOnlyCompileOptions &options,
            const char *bytes, size_t length, JS::MutableHandleScript script);

bool
JS::Compile(JSContext *cx,
            const JS::ReadOnlyCompileOptions &options,
            const char16_t *chars, size_t length, JS::MutableHandleScript script);

bool
JS::Compile(JSContext *cx,
            const JS::ReadOnlyCompileOptions &options, FILE *file,
            JS::MutableHandleScript script);

bool
JS::Compile(JSContext *cx,
            const JS::ReadOnlyCompileOptions &options, const char *filename,
            JS::MutableHandleScript script);

// Obsolete since JSAPI 39

bool
JS::Compile(JSContext *cx, JS::HandleObject obj,
            const JS::ReadOnlyCompileOptions &options,
            JS::SourceBufferHolder &srcBuf, JS::MutableHandleScript script);

bool
JS::Compile(JSContext *cx, JS::HandleObject obj,
            const JS::ReadOnlyCompileOptions &options,
            const char *bytes, size_t length, JS::MutableHandleScript script);

bool
JS::Compile(JSContext *cx, JS::HandleObject obj,
            const JS::ReadOnlyCompileOptions &options,
            const char16_t *chars, size_t length, JS::MutableHandleScript script);

bool
JS::Compile(JSContext *cx, JS::HandleObject obj,
            const JS::ReadOnlyCompileOptions &options, FILE *file,
            JS::MutableHandleScript script);

bool
JS::Compile(JSContext *cx, JS::HandleObject obj,
            const JS::ReadOnlyCompileOptions &options, const char *filename,
            JS::MutableHandleScript script);
NameTypeDescription
cxJSContext *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.
objJS::HandleObjectThe global object, or NULL. Obsolete since JSAPI 39
optionsJS::ReadOnlyCompileOptions &Compile options.
srcBufJS::SourceBufferHolder &Source buffer containing the script to compile.
charsconst char16_t *String containing the script to compile.
bytesconst char *String containing the script to compile.
lengthsize_tThe length of chars or bytes, in characters.
fileFILE *File handle containing the function.
filenameconst char *Name of file or URL containing the function. Used to report filename or URL in error messages.
scriptJS::MutableHandleScriptOut parameter. On success, script receives the result script.

Description

JS::Compile compiles a script, srcBuf, chars, bytes, or file, for execution.

The script is associated with a JS object. srcBuf, chars, bytes is the string containing the text of the script. length indicates the size of the text version of the script in characters.

file is the filehandle containing the text of the script.

filename is the name of the file (or URL) containing the script. This information is included in error messages if an error occurs during compilation..

On success, JS::Compile stores an object representing the newly compiled script into script, and returns true. Otherwise, it returns false and the value left in script is undefined.

See Also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:136 次

字数:6623

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文