JS_ExecuteScript

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_ExecuteScript
  • Revision title: JS_ExecuteScript
  • Revision id: 77497
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment style

Revision Content

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

Executes a compiled script.

Syntax

JSBool JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script,
    jsval *rval);
Name Type Description
cx JSContext * JS context in which the script executes. {{wiki.template('Jsapi-requires-request')}}
obj JSObject * Object with which the script is associated.
script JSScript * Previously compiled script to execute.
rval jsval * Pointer to the value from the last executed expression statement processed in the script.

Description

JS_ExecuteScript executes a previously compiled script, script. On successful completion, *rval receives the value from the last executed expression statement processed in the script.

If a script executes successfully, JS_ExecuteScript returns JS_TRUE. Otherwise it returns JS_FALSE, and the value left in *rval is unspecified.

To execute an uncompiled script, compile it with JS_CompileScript or JS_CompileFile, and then call JS_ExecuteScript, followed b JS_DestroyScript. Or, call JS_EvaluateScript to both compile and execute the script.

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

Revision Source

<p>{{template.Jsapi_ref_header("JS_ExecuteScript")}}
</p><p>Executes a compiled script.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="en/JSBool">JSBool</a> <b>JS_ExecuteScript</b>(<a href="en/JSContext">JSContext</a> *cx, <a href="en/JSObject">JSObject</a> *obj, <a href="en/JSScript">JSScript</a> *script,
    <a href="en/Jsval">jsval</a> *rval);
</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>JS context in which the script executes.
{{wiki.template('Jsapi-requires-request')}}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code><a href="en/JSObject">JSObject</a> *</code></td>
<td>Object with which the script is associated.</td>
</tr>
<tr>
<td><code>script</code></td>
<td><code><a href="en/JSScript">JSScript</a> *</code></td>
<td>Previously compiled script to execute.</td>
</tr>
<tr>
<td><code>rval</code></td>
<td><code><a href="en/Jsval">jsval</a> *</code></td>
<td>Pointer to the value from the last executed expression statement processed in the script.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><b><code>JS_ExecuteScript</code></b> executes a previously compiled script, <code>script</code>. On successful completion, <code>*rval</code> receives the value from the last executed expression statement processed in the script.
</p><p>If a script executes successfully, <code>JS_ExecuteScript</code> returns <code>JS_TRUE</code>. Otherwise it returns <code>JS_FALSE</code>, and the value left in <code>*rval</code> is unspecified.
</p><p>To execute an uncompiled script, compile it with <code><a href="en/JS_CompileScript">JS_CompileScript</a></code> or <code><a href="en/JS_CompileFile">JS_CompileFile</a></code>, and then call <code>JS_ExecuteScript</code>, followed b <code><a href="en/JS_DestroyScript">JS_DestroyScript</a></code>.  Or, call <code><a href="en/JS_EvaluateScript">JS_EvaluateScript</a></code> to both compile and execute the script.
</p><p>{{template.LXRSearch("ident", "i", "JS_ExecuteScript")}}
</p>
Revert to this revision