JS CompileScript
From MDC
Compiles a script for execution.
[edit] Syntax
JSScript * JS_CompileScript(JSContext *cx, JSObject *obj, const char *bytes, size_t length, const char *filename, uintN lineno); JSScript * JS_CompileUCScript(JSContext *cx, JSObject *obj, const jschar *chars, size_t length, const char *filename, uintN lineno);
| Name | Type | Description |
|---|---|---|
cx |
JSContext * |
Pointer to a JS context from which to derive runtime information.
Requires request. (In a |
obj |
JSObject * |
Object with which the script is associated. |
source |
const char * or const jschar * |
String containing the script to compile. |
length |
size_t |
The length, in characters, of source. |
filename |
const char * |
Name of file or URL containing the function. Used to report filename or URL in error messages. |
lineno |
uintN |
Line number of the first line of source. Must be greater than zero. Used to report the offending line in the file or URL if an error occurs. |
[edit] Description
JS_CompileScript compiles a script, source, for execution. JS_CompileUCScript is the Unicode version of the function.
The script is associated with a JS object. bytes is the string containing the text of the script. length indicates the size of the text version of the script in bytes.
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. If the script is not part of a larger document, lineno should be 1 (as the first line of a file is universally considered to be line 1, not line 0).
On success, JS_CompileScript and JS_CompileUCScript return a pointer to the newly compiled script. Otherwise, they report an error and 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.
To compile a script from an external file source rather than passing the actual script as an argument, use JS_CompileFile instead of JS_CompileScript.
[edit] See Also
The JSAPI User Guide contains example code using compiled scripts.
LXR ID Search for JS_CompileScript
LXR ID Search for JS_CompileUCScript