JS EvaluateScript
From MDC
Compile and execute a script.
[edit] Syntax
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);
| Name | Type | Description |
|---|---|---|
cx |
JSContext * |
The context in which to run the script.
Requires request. (In a |
obj |
JSObject * |
The scope in which to execute the script.
This parameter is documented in detail at JS_ExecuteScript. |
src |
const char * or const jschar * |
String containing the script to compile and execute. |
length |
uintN |
The length of src, in characters. |
filename |
const char * |
Name of file or URL containing the script. Used to report filename or URL in error messages. |
lineno |
uintN |
Line number. Used to report the offending line in the file or URL if an error occurs. |
rval |
jsval * |
Out parameter. On success, *rval receives the value of the last-executed expression statement processed in the script. |
[edit] Description
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.
[edit] See Also
LXR ID Search for JS_EvaluateScript
LXR ID Search for JS_EvaluateUCScript
JS_CompileFile, JS_CompileScript, JS_DecompileScript, JS_DestroyScript, JS_EvaluateScriptForPrincipals