JS_CompileFunctionForPrincipals 编辑

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.

Create a security-enabled JS function from a text string.

Syntax

JSFunction *
JS_CompileFunctionForPrincipals(JSContext *cx,
    JSObject *obj, JSPrincipals *principals, const char *name,
    unsigned int nargs, const char **argnames, const char *body,
    size_t length, const char *filename, unsigned int lineno);

JSFunction *
JS_CompileUCFunctionForPrincipals(JSContext *cx,
    JSObject *obj, JSPrincipals *principals, const char *name,
    unsigned int nargs, const char **argnames, const jschar *body,
    size_t length, const char *filename, unsigned int lineno);
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.
objJSObject *Object with which the function is to be associated.
principalsJSPrincipals *Pointer to the structure holding the security information for this function.
nameconst char *Name to assign the newly compiled function.
nargsunsigned intNumber of arguments to pass to the function.
argnamesconst char **Names to assign to the arguments passed to the function.
bodyconst char * or const jschar *String containing the source code of the function to compile.
lengthsize_tThe length, in characters, of body.
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.

Description

JS_CompileFunctionForPrincipals compiles a security-enabled function from a text string, bytes, and associates it with a JS object, obj. JS_CompileUCFunctionForPrincipals is the Unicode version of the function.

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

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.

body is the string containing the source code of the function. length is the length of the string in characters.

filename is the name of the file (or URL) containing the function. This information is passed in messages if an error occurs during compilation. Similarly, lineno is used to report the line number of the function or file where an error occurred during compilation.

On success, JS_CompileFunctionForPrincipals and JS_CompileUCFunctionForPrincipals return a pointer to the newly compiled function. On error or exception, they return NULL.

See Also

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

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

发布评论

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

词条统计

浏览:96 次

字数:7605

最后编辑:7年前

编辑次数:0 次

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