JS_CompileScriptForPrincipals 编辑

Obsolete since JSAPI 28
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.

Compile a security-enabled script for execution.

Syntax

JSScript *
JS_CompileScriptForPrincipals(JSContext *cx,
    JSObject *obj, JSPrincipals *principals, const char *src,
    size_t length, const char *filename, unsigned int lineno);

JSScript *
JS_CompileUCScriptForPrincipals(JSContext *cx,
    JSObject *obj, JSPrincipals *principals, const jschar *src,
    size_t length, const char *filename, unsigned int lineno);

JSObject *
JS_CompileScriptForPrincipalsVersion(JSContext *cx,
    JSObject *obj, JSPrincipals *principals, const char *src, size_t length,
    const char *filename, unsigned int lineno, JSVersion version); // Obsoleted since JSAPI 19

JSObject *
JS_CompileUCScriptForPrincipalsVersion(JSContext *cx,
    JSObject *obj, JSPrincipals *principals, const jschar *src,
    size_t length, const char *filename, unsigned int lineno, JSVersion version); // Obsoleted since JSAPI 19
NameTypeDescription
cxJSContext *The context in which to compile the script. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
objJSObject *Object with which the script is associated.
principalsJSPrincipals *Pointer to the structure holding the security information for this script.
srcconst char * or const jschar *String containing the script to compile.
lengthsize_tThe length of src, in characters.
filenameconst char *Name of file or URL containing the function. Used to report filename or URL in error messages.
linenounsigned intLine number. Used to report the offending line in the file or URL if an error occurs.
versionJSVersionJavaScript Version for the script.

Description

JS_CompileScriptForPrincipals compiles a security-enabled script, src, for execution. JS_CompileUCScriptForPrincipals is the Unicode version of the function. The script is associated with a JS object.

principals is a pointer to the JSPrincipals structure that contains the security information to associate with this script.

src is the string containing the text of the script. length indicates the length of the script, in characters.

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. Similarly, lineno is used to report the line number of the script or file where an error occurred during compilation.

On success, JS_CompileScriptForPrincipals and JS_CompileUCScriptForPrincipals return a pointer to the compiled script. On error or exception, they return NULL.

The application is responsible for ensuring that the new compiled script is cleaned up later—either by calling JS_DestroyScript() directly or by calling JS_NewScriptObject(), in which case the garbage collector cleans up the script.

Warning: This API is subject to bug 438633, which can cause crashes in almost any program that uses JS_DestroyScript(). The workaround is to use JS_NewScriptObject() to root each newly-compiled script, as described in the JSAPI User Guide under Compiled scripts.

See Also

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

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

发布评论

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

词条统计

浏览:130 次

字数:6588

最后编辑:7年前

编辑次数:0 次

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