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);
NameTypeDescription
cxJSContext *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.
scopeChainJS::AutoObjectVector &The scope in which to compile the function.
optionsJS::ReadOnlyCompileOptions &Compile options.
nameconst char *Name to assign the newly compiled function.
nargsunsignedNumber of arguments to pass to the function.
argnamesconst char *const *Names to assign to the arguments passed to the function.
charsconst char16_t *String containing the body of the function to compile.
bytesconst char *String containing the body of the function to compile.
lengthsize_tThe length, in characters, of body.
srcBufJS::SourceBufferHolder &Source buffer containing the script function compile.
funJS::MutableHandleFunctionOut 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

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

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

发布评论

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

词条统计

浏览:143 次

字数:5971

最后编辑:6年前

编辑次数:0 次

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