JS_CompileUTF8FileHandle

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

Revision Content

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

Compile a script, reading the source code from a stdio FILE.

Syntax

JSScript * JS_CompileFileHandle(JSContext *cx, JSObject *obj,
    const char *filename, FILE *file);

JSScript * JS_CompileFileHandleForPrincipals(
    JSContext *cx, JSObject *obj,
    const char *filename, FILE *file, JSPrincipals *principals);


Name Type Description
cx JSContext * The context in which to compile the script. {{wiki.template('Jsapi-requires-request')}}
obj JSObject * Object with which the script is associated.
filename const char * Filename to associate with the compiled script. This filename is used for error messages. It should be the name of the file that contains the script, if available.
file FILE * The file handle containing the script to compile.
principals JSPrincipals * (only in JS_CompileFileHandleForPrincipals) The security principals to associate with the new script, or NULL.

Description

JS_CompileFileHandle reads a script from a stdio file handle and compiles the script for execution by the JavaScript engine. JS_CompileFileHandleForPrincipals is a version of the function for use with SpiderMonkey's security features.

filename is the name of the file containing the script to compile. file is the file handle. JS_CompileFileHandle does not close the file handle.

If principals is non-null, it points to a JSPrincipals object that is associated with the new script and any functions it creates.

On success, JS_CompileFileHandle reads file to EOF and returns a pointer to the compiled script. If an error occurs during compilation, JS_CompileFile stops reading from the file and returns NULL.

{{template.Jsapi_new_script_warning("JS_CompileFileHandle")}}

{{template.Jsapi_compiled_script_example_pointer()}}

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

Revision Source

<p>{{template.Jsapi_ref_header("JS_CompileFileHandle")}}
</p><p>Compile a script, reading the source code from a <code>stdio</code> <code>FILE</code>.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="en/JSScript">JSScript</a> * <b>JS_CompileFileHandle</b>(<a href="en/JSContext">JSContext</a> *cx, <a href="en/JSObject">JSObject</a> *obj,
    const char *filename, FILE *file);

<a href="en/JSScript">JSScript</a> * <b>JS_CompileFileHandleForPrincipals</b>(
    <a href="en/JSContext">JSContext</a> *cx, <a href="en/JSObject">JSObject</a> *obj,
    const char *filename, FILE *file, <a href="en/JSPrincipals">JSPrincipals</a> *principals);
</pre>
<p><br>
</p>
<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 compile the script.
{{wiki.template('Jsapi-requires-request')}}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code>JSObject *</code></td>
<td>Object with which the script is associated.</td>
</tr>
<tr>
<td><code>filename</code></td>
<td><code>const char *</code></td>
<td>Filename to associate with the compiled script.  This filename is used for error messages.  It should be the name of the file that contains the script, if available.</td>
</tr>
<tr>
<td><code>file</code></td>
<td><code>FILE *</code></td>
<td>The file handle containing the script to compile.</td>
</tr>
<tr>
<td><code>principals</code></td>
<td><code><a href="en/JSPrincipals">JSPrincipals</a> *</code></td>
<td><i>(only in <code>JS_CompileFileHandleForPrincipals</code>)</i> The security principals to associate with the new script, or <code>NULL</code>.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_CompileFileHandle</code> reads a script from a <code>stdio</code> file handle and compiles the script for execution by the JavaScript engine.  <code>JS_CompileFileHandleForPrincipals</code> is a version of the function for use with SpiderMonkey's security features.
</p><p><code>filename</code> is the name of the file containing the script to compile.  <code>file</code> is the file handle.  <code>JS_CompileFileHandle</code> does not close the file handle.
</p><p>If <code>principals</code> is non-null, it points to a <code><a href="en/JSPrincipals">JSPrincipals</a></code> object that is associated with the new script and any functions it creates.
</p><p>On success, <code>JS_CompileFileHandle</code> reads <code>file</code> to EOF and returns a pointer to the compiled script.  If an error occurs during compilation, <code>JS_CompileFile</code> stops reading from the file and returns <code>NULL</code>.
</p><p>{{template.Jsapi_new_script_warning("JS_CompileFileHandle")}}
</p><p>{{template.Jsapi_compiled_script_example_pointer()}}
</p><p>{{template.LXRSearch("ident", "i", "JS_CompileFileHandle")}}
</p>
Revert to this revision