JS_NewScriptObject

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_NewScriptObject
  • Revision title: JS_NewScriptObject
  • Revision id: 106876
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment /* Description */

Revision Content

{{template.Jsapi_ref_header("JS_NewScriptObject")}}

Create a new JavaScript object for a compiled script. This is very often necessary to prevent parts of the script from being 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. {{wiki.template('Jsapi-requires-request')}}
script JSScript * The compiled script for which to create a new script object.

Description

JS_NewScriptObject wraps the given script in a new JavaScript object. As long as the new JSObject is reachable, the JSScript and its components are protected from garbage collected. (There are several ways to ensure that an object remains reachable. The most common are JS_AddRoot and JS_EnterLocalRootScope.)

The object created by JS_NewScriptObject has no properties, and its prototype is Object.prototype. So this can be used to expose a JSScript to JavaScript code, but a script can't do much of anything with it.

On success, JS_NewScriptObject returns a pointer to the newly created object. Otherwise it returns NULL.

{{template.LXRSearch("ident", "i", "JS_NewScriptObject")}}

Revision Source

<p>{{template.Jsapi_ref_header("JS_NewScriptObject")}}
</p><p>Create a new JavaScript object for a <a href="en/JS_CompileScript">compiled script</a>.  This is very often necessary to prevent parts of the script from being garbage collected.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="en/JSObject">JSObject</a> * <b>JS_NewScriptObject</b>(<a href="en/JSContext">JSContext</a> *cx, <a href="en/JSScript">JSScript</a> *script);
</pre>
<table class="fullwidth-table">
<tbody><tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code>cx</code></td>
<td><code><a href="en/JSContext">JSContext</a> *</code></td>
<td>The context in which to create the new script object.
{{wiki.template('Jsapi-requires-request')}}</td>
</tr>
<tr>
<td><code>script</code></td>
<td><code><a href="en/JSScript">JSScript</a> *</code></td>
<td>The compiled script for which to create a new script object.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_NewScriptObject</code> wraps the given <code>script</code> in a new JavaScript object.  As long as the new <code>JSObject</code> is reachable, the <code>JSScript</code> and its components are protected from garbage collected.  (There are several ways to ensure that an object remains reachable.  The most common are <code><a href="en/JS_AddRoot">JS_AddRoot</a></code> and <code><a href="en/JS_EnterLocalRootScope">JS_EnterLocalRootScope</a></code>.)
</p><p>The object created by <code>JS_NewScriptObject</code> has no properties, and its prototype is <code>Object.prototype</code>.  So this can be used to expose a <code>JSScript</code> to JavaScript code, but a script can't do much of anything with it.
</p><p>On success, <code>JS_NewScriptObject</code> returns a pointer to the newly created object.  Otherwise it returns <code>NULL</code>.
</p><p>{{template.LXRSearch("ident", "i", "JS_NewScriptObject")}}
</p>
Revert to this revision