JS_CompileScriptForPrincipals

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_CompileScriptForPrincipals
  • Revision title: JS_CompileScriptForPrincipals
  • Revision id: 147175
  • Created:
  • Creator: Jorend
  • Is current revision? Yes
  • Comment 14 words removed

Revision Content

Compile a security-enabled script for execution.

Syntax

JSScript * JS_CompileScriptForPrincipals(JSContext *cx,
    JSObject *obj, JSPrincipals *principals, const char *src,
    size_t length, const char *filename, uintN lineno);

JSScript * JS_CompileUCScriptForPrincipals(JSContext *cx,
    JSObject *obj, JSPrincipals *principals, const jschar *src,
    size_t length, const char *filename, uintN lineno);
Name Type Description
cx JSContext * The context in which to compile the script. {{ Jsapi-requires-request() }}
obj JSObject * Object with which the script is associated.
principals JSPrincipals * Pointer to the structure holding the security information for this script.
src const char * or const jschar * String containing the script to compile.
length size_t The length of src, in characters.
filename const char * Name of file or URL containing the function. Used to report filename or URL in error messages.
lineno uintN Line number. Used to report the offending line in the file or URL if an error occurs.

Description

JS_CompileScriptForPrincipals compiles a security-enabled script, src, for execution. JS_CompileUCScriptForPrincipals is the Unicode version of the function. The script is associated with a JS object.

principals is a pointer to the JSPrincipals structure that contains the security information to associate with this script.

src is the string containing the text of the script. length indicates the length of the script, in characters.

filename is the name of the file (or URL) containing the script. This information is included in error messages if an error occurs during compilation. Similarly, lineno is used to report the line number of the script or file where an error occurred during compilation.

On success, JS_CompileScriptForPrincipals and JS_CompileUCScriptForPrincipals return a pointer to the compiled script. On error or exception, they return NULL.

{{ Jsapi_script_lifetime() }}

See Also

{{ LXRSearch("ident", "i", "JS_CompileScriptForPrincipals") }}
{{ LXRSearch("ident", "i", "JS_CompileUCScriptForPrincipals") }}

JS_CompileFile, JS_CompileUCScript, JS_DecompileScript, JS_DestroyScript, JS_EvaluateScript, JS_EvaluateScriptForPrincipals, JS_ExecuteScript

Revision Source

<p>Compile a security-enabled script for execution.
</p>
<h2 id="Syntax" name="Syntax"> Syntax </h2>
<pre class="eval"><a href="/en/JSScript" title="en/JSScript">JSScript</a> * <strong>JS_CompileScriptForPrincipals</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx,
    <a href="/en/SpiderMonkey/JSAPI_Reference/JSObject" title="en/JSObject">JSObject</a> *obj, <a href="/en/SpiderMonkey/JSAPI_Reference/JSPrincipals" title="en/JSPrincipals">JSPrincipals</a> *principals, const char *src,
    size_t length, const char *filename, <a href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">uintN</a> lineno);

<a href="/en/JSScript" title="en/JSScript">JSScript</a> * <strong>JS_CompileUCScriptForPrincipals</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx,
    <a href="/en/SpiderMonkey/JSAPI_Reference/JSObject" title="en/JSObject">JSObject</a> *obj, <a href="/en/SpiderMonkey/JSAPI_Reference/JSPrincipals" title="en/JSPrincipals">JSPrincipals</a> *principals, const <a href="/en/SpiderMonkey/JSAPI_Reference/jschar" title="en/jschar">jschar</a> *src,
    size_t length, const char *filename, <a href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">uintN</a> lineno);
</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/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td>
<td>The context in which to compile the script.
{{ Jsapi-requires-request() }}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSObject" title="en/JSObject">JSObject</a> *</code></td>
<td>Object with which the script is associated.</td>
</tr>
<tr>
<td><code>principals</code></td>
<td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSPrincipals" title="en/JSPrincipals">JSPrincipals</a> *</code></td>
<td>Pointer to the structure holding the security information for this script.</td>
</tr>
<tr>
<td><code>src</code></td>
<td><code>const char *</code> <em>or</em> <code>const <a href="/en/SpiderMonkey/JSAPI_Reference/jschar" title="en/jschar">jschar</a> *</code></td>
<td>String containing the script to compile.</td>
</tr>
<tr>
<td><code>length</code></td>
<td><code>size_t</code></td>
<td>The length of <code>src</code>, in characters.</td>
</tr>
<tr>
<td><code>filename</code></td>
<td><code>const char *</code></td>
<td>Name of file or URL containing the function. Used to report filename or URL in error messages.</td>
</tr>
<tr>
<td><code>lineno</code></td>
<td><code>uintN</code></td>
<td>Line number. Used to report the offending line in the file or URL if an error occurs.</td>
</tr>
</tbody></table>
<h2 id="Description" name="Description"> Description </h2>
<p><code>JS_CompileScriptForPrincipals</code> compiles a security-enabled script, <code>src</code>, for execution. <code>JS_CompileUCScriptForPrincipals</code> is the Unicode version of the function. The script is associated with a JS object.
</p><p><code>principals</code> is a pointer to the <code>JSPrincipals</code> structure that contains the security information to associate with this script.
</p><p><code>src</code> is the string containing the text of the script. <code>length</code> indicates the length of the script, in characters.
</p><p><code>filename</code> is the name of the file (or URL) containing the script. This information is included in error messages if an error occurs during compilation. Similarly, <code>lineno</code> is used to report the line number of the script or file where an error occurred during compilation.
</p><p>On success, <code>JS_CompileScriptForPrincipals</code> and <code>JS_CompileUCScriptForPrincipals</code> return a pointer to the compiled script. On error or exception, they return <code>NULL</code>.
</p><p>{{ Jsapi_script_lifetime() }}
</p>
<h2 id="See_Also" name="See_Also"> See Also </h2>
<p>{{ LXRSearch("ident", "i", "JS_CompileScriptForPrincipals") }}<br>
{{ LXRSearch("ident", "i", "JS_CompileUCScriptForPrincipals") }}
</p><p><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileFile" title="en/JS_CompileFile">JS_CompileFile</a>,
<a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileScript" title="en/JS_CompileScript">JS_CompileUCScript</a>,
<a href="/en/SpiderMonkey/JSAPI_Reference/JS_DecompileScript" title="en/JS_DecompileScript">JS_DecompileScript</a>,
<a href="/en/SpiderMonkey/JSAPI_Reference/JS_DestroyScript" title="en/JS_DestroyScript">JS_DestroyScript</a>,
<a href="/en/SpiderMonkey/JSAPI_Reference/JS_EvaluateScript" title="en/JS_EvaluateScript">JS_EvaluateScript</a>,
<a href="/en/SpiderMonkey/JSAPI_Reference/JS_EvaluateScriptForPrincipals" title="en/JS_EvaluateScriptForPrincipals">JS_EvaluateScriptForPrincipals</a>,
<a href="/en/SpiderMonkey/JSAPI_Reference/JS_ExecuteScript" title="en/JS_ExecuteScript">JS_ExecuteScript</a>
</p>
Revert to this revision