From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../jsapi_reference/js_evaluatescript/index.html | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_evaluatescript/index.html (limited to 'files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_evaluatescript/index.html') diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_evaluatescript/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_evaluatescript/index.html new file mode 100644 index 0000000000..94454ee794 --- /dev/null +++ b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_evaluatescript/index.html @@ -0,0 +1,69 @@ +--- +title: SpiderMonkey/JSAPI_参考/JS_EvaluateScript +slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_EvaluateScript +translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_EvaluateScript +--- +

编译并执行一个脚本。

+

语法

+
JSBool JS_EvaluateScript(JSContext *cx, JSObject *obj,
+    const char *src, uintN length, const char *filename,
+    uintN lineno, jsval *rval);
+
+JSBool JS_EvaluateUCScript(JSContext *cx, JSObject *obj,
+    const jschar *src, uintN length, const char *filename,
+    uintN lineno, jsval *rval);
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
名称数据类型描述
cxJSContext *脚本运行的上下文. {{ Jsapi-requires-request() }}
objJSObject *The scope in which to execute the script. This parameter is documented in detail at JS_ExecuteScript.
srcconst char * or const jschar *包含要编译和执行的脚本的字符串.
lengthuintNsrc的长度, in characters.
filenameconst char *Name of file or URL containing the script. Used to report filename or URL in error messages.
linenouintNLine number. Used to report the offending line in the file or URL if an error occurs.
rvaljsval *Out parameter. On success, *rval receives the value of the last-executed expression statement processed in the script.
+

描述

+

JS_EvaluateScript compiles and executes a script in the specified scope, obj. On successful completion, rval is a pointer to a variable that holds the value from the last executed expression statement processed in the script. 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.

+

If a script compiles and executes successfully, *rval receives the value from the last-executed expression statement in the script, and JS_EvaluateScript or JS_EvaluateUCScript returns JS_TRUE. Otherwise it returns JS_FALSE and the value left in *rval is undefined.

+

See Also

+

{{ LXRSearch("ident", "i", "JS_EvaluateScript") }}
+ {{ LXRSearch("ident", "i", "JS_EvaluateUCScript") }}

+

JS_CompileFile, JS_CompileScript, JS_DecompileScript, JS_DestroyScript, JS_EvaluateScriptForPrincipals

+

{{ languages( { "ja": "ja/JS_EvaluateScript" } ) }}

-- cgit v1.2.3-54-g00ecf