JS_DecompileScript

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_DecompileScript
  • Revision title: JS_DecompileScript
  • Revision id: 147134
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment no wording changes; page display name changed to 'JS_DecompileScript'

Revision Content

{{ Jsapi_ref_header("JS_DecompileScript") }}

Creates the source code of a script from a script's compiled form.

Syntax

JSString * JS_DecompileScript(JSContext *cx, JSScript *script,
   const char *name, uintN indent);
Name Type Description
cx JSContext * The context to use to decompile the script. {{ Jsapi-requires-request() }}
script JSScript * Script to decompile.
name const char * Name to assign to the decompiled script.
indent uintN Number of spaces to use for indented code.

Description

JS_DecompileScript creates the source code version of a script from a script's compiled form, script. name is the name you assign to the text version of the script; it is used only for debugging the source code version produced by this function.

If successful, JS_DecompileScript returns a string containing the source code of the script. Otherwise, it returns NULL. The source code generated by this function is accurate but lacks function declarations. In order to make it suitable for recompiling, you must edit the code to add the function declarations, or call JS_DecompileFunction on a compiled version of each function to generate the function declarations.

See Also

{{ LXRSearch("ident", "i", "JS_DecompileScript") }}

JS_CompileFile, JS_CompileScript, JS_DecompileFunction, JS_DestroyScript, JS_EvaluateScript, JS_ExecuteScript

Revision Source

<p>{{ Jsapi_ref_header("JS_DecompileScript") }}
</p><p>Creates the source code of a script from a script's compiled form.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="/en/JSString" title="en/JSString">JSString</a> * <strong>JS_DecompileScript</strong>(<a href="/en/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/en/JSScript" title="en/JSScript">JSScript</a> *script,
   const char *name, <a href="/en/jsint" title="en/jsint">uintN</a> indent);
</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/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td>
<td>The context to use to decompile the script.
{{ Jsapi-requires-request() }}</td>
</tr>
<tr>
<td><code>script</code></td>
<td><code><a href="/en/JSScript" title="en/JSScript">JSScript</a> *</code></td>
<td>Script to decompile.</td>
</tr>
<tr>
<td><code>name</code></td>
<td><code>const char *</code></td>
<td>Name to assign to the decompiled script.</td>
</tr>
<tr>
<td><code>indent</code></td>
<td><code><a href="/en/jsint" title="en/jsint">uintN</a></code></td>
<td>Number of spaces to use for indented code.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_DecompileScript</code> creates the source code version of a script from a script's compiled form, <code>script</code>. <code>name</code> is the name you assign to the text version of the script; it is used only for debugging the source code version produced by this function.
</p><p>If successful, <code>JS_DecompileScript</code> returns a string containing the source code of the script. Otherwise, it returns <code>NULL</code>. The source code generated by this function is accurate but lacks function declarations. In order to make it suitable for recompiling, you must edit the code to add the function declarations, or call <code><a href="/en/JS_DecompileFunction" title="en/JS_DecompileFunction">JS_DecompileFunction</a></code> on a compiled version of each function to generate the function declarations.
</p>
<h2 name="See_Also"> See Also </h2>
<p>{{ LXRSearch("ident", "i", "JS_DecompileScript") }}
</p><p><a href="/en/JS_CompileFile" title="en/JS_CompileFile">JS_CompileFile</a>,
<a href="/en/JS_CompileScript" title="en/JS_CompileScript">JS_CompileScript</a>,
<a href="/en/JS_DecompileFunction" title="en/JS_DecompileFunction">JS_DecompileFunction</a>,
<a href="/en/JS_DestroyScript" title="en/JS_DestroyScript">JS_DestroyScript</a>,
<a href="/en/JS_EvaluateScript" title="en/JS_EvaluateScript">JS_EvaluateScript</a>,
<a href="/en/JS_ExecuteScript" title="en/JS_ExecuteScript">JS_ExecuteScript</a>
</p>
Revert to this revision