Obsolete since JSAPI 8
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.
Return the JavaScript script object that wraps a compiled script. The compiled script and its parts live until the script object is garbage collected.
Syntax
JSObject * JS_NewScriptObject(JSContext *cx, JSScript *script);
Name | Type | Description |
---|---|---|
cx |
JSContext * |
The context in which to create the new script object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
script |
JSScript * |
The compiled script for which to create a new script object. |
Description
JS_NewScriptObject
returns the script object associated with the given JSScript
.
Every JSScript object has an associated JSObject script object. As long as the script object is reachable, the JSScript and its components are protected from garbage collection; when the script object is collected, the JSScript and its contents are freed. Once you have created a script, you should immediately ensure that its script object is reachable (perhaps by using JS_AddRoot
or JS_EnterLocalRootScope
).
A script object has no properties, and its prototype is Object.prototype
. So a script object can be used to expose a
to JavaScript code, but the code can't do much of anything with it.JSScript
On success, JS_NewScriptObject
returns a pointer to the script's object. Otherwise it returns NULL
.
(The name "JS_NewScriptObject
" suggests that the script object is freshly allocated; this was the case in older versions of the API, but now the script object is allocated along with the JSScript itself.)
(Some temporary scripts used internally by SpiderMonkey do not have script objects allocated for them; such scripts are not accessible via JSAPI.)
See Also
- The JSAPI User Guide contains example code using compiled scripts.
- MXR ID Search for
JS_NewScriptObject
- bug 630209