JS_EvaluateScript 编辑

Obsolete since JSAPI 36
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 and execute a script.

Syntax

JSBool
JS_EvaluateScript(JSContext *cx, JSObject *obj,
    const char *src, unsigned int length, const char *filename,
    unsigned int lineno, jsval *rval);

JSBool
JS_EvaluateUCScript(JSContext *cx, JSObject *obj,
    const jschar *src, unsigned int length, const char *filename,
    unsigned int lineno, jsval *rval);
NameTypeDescription
cxJSContext *The context in which to run the script. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
objJSObject *The scope in which to execute the script. This parameter is documented in detail at JS_ExecuteScript.
srcconst char * or const jschar *String containing the script to compile and execute.
lengthunsigned intThe length of src, in characters.
filenameconst char *Name of file or URL containing the script. 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.
rvaljsval *Out parameter. On success, if rval is not NULL, *rval receives the result value.

Description

JS_EvaluateScript compiles and executes a script in the specified scope, obj. JS_EvaluateUCScript is the Unicode version of the function.

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

filename is the name of the file (or URL) containing the script. This information is used in 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.

rval is an optional out parameter. If it is non-null, then on success, the result value is stored in *rval. This value is determined the same way as for the standard eval function. In the common case where the script is just an expression, the result value is simply the value of that expression. More generally, the result value is the value of the last-executed expression statement in the script that isn't in a function.

If a script compiles and executes successfully, JS_EvaluateScript or JS_EvaluateUCScript stores the result in *rval, if non-null, and returns JS_TRUE. Otherwise it returns JS_FALSE and the value left in *rval is undefined.

See Also

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

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

发布评论

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

词条统计

浏览:77 次

字数:5623

最后编辑:6年前

编辑次数:0 次

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