JS_EvaluateScriptForPrincipals

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_EvaluateScriptForPrincipals
  • Revision title: JS_EvaluateScriptForPrincipals
  • Revision id: 147078
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment /* Syntax */ fmt

Revision Content

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

Compile and execute a security-enabled script.

Syntax

JSBool JS_EvaluateScriptForPrincipals(JSContext *cx,
    JSObject *obj, JSPrincipals *principals, const char *src,
    uintN length, const char *filename, uintN lineno,
    jsval *rval);

JSBool JS_EvaluateScriptUCForPrincipals(JSContext *cx,
   JSObject *obj, JSPrincipals *principals, const jschar *src,
   uintN length, const char *filename, uintN lineno,
   jsval *rval);


Name Type Description
cx JSContext * The context in which to run the script. {{wiki.template('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 and execute.
length size_t The length of src, in characters.
filename const char * Name of file or URL containing the script. 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.
rval jsval * Out parameter. On success, *rval receives the value from the last executed expression statement processed in the script.

Description

JS_EvaluateScriptForPrincipals compiles and executes a script associated with a JS object, obj. JS_EvaluateUCScriptForPrincipals is the Unicode version of the function.

On successful completion, *rval receives the value from the last executed expression statement processed in the script.

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 used in 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.

If a secure script compiles and executes successfully, JS_EvaluateScriptForPrincipals returns JS_TRUE. Otherwise it returns JS_FALSE, and the value left in *rval is undefined.

See Also

{{template.LXRSearch("ident", "i", "JS_EvaluateScriptForPrincipals")}}
{{template.LXRSearch("ident", "i", "JS_EvaluateUCScriptForPrincipals")}}

JS_CompileFile, JS_CompileScriptForPrincipals, JS_EvaluateScript

Revision Source

<p>{{template.Jsapi_ref_header("JS_EvaluateScriptForPrincipals")}}
</p><p>Compile and execute a security-enabled script.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval"><a href="en/JSBool">JSBool</a> <b>JS_EvaluateScriptForPrincipals</b>(<a href="en/JSContext">JSContext</a> *cx,
    <a href="en/JSObject">JSObject</a> *obj, <a href="en/JSPrincipals">JSPrincipals</a> *principals, const char *src,
    <a href="en/UintN">uintN</a> length, const char *filename, <a href="en/UintN">uintN</a> lineno,
    <a href="en/Jsval">jsval</a> *rval);

<a href="en/JSBool">JSBool</a> <b>JS_EvaluateScriptUCForPrincipals</b>(<a href="en/JSContext">JSContext</a> *cx,
   <a href="en/JSObject">JSObject</a> *obj, <a href="en/JSPrincipals">JSPrincipals</a> *principals, const <a href="en/Jschar">jschar</a> *src,
   <a href="en/UintN">uintN</a> length, const char *filename, <a href="en/UintN">uintN</a> lineno,
   <a href="en/Jsval">jsval</a> *rval);
</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 run the script.
{{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>principals</code></td>
<td><code><a href="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> <i>or</i> <code>const <a href="en/Jschar">jschar</a> *</code></td>
<td>String containing the script to compile and execute.</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 script. Used to report filename or URL in error messages.</td>
</tr>
<tr>
<td><code>lineno</code></td>
<td><code><a href="en/UintN">uintN</a></code></td>
<td>Line number. Used to report the offending line in the file or URL if an error occurs.</td>
</tr>
<tr>
<td><code>rval</code></td>
<td><code><a href="en/Jsval">jsval</a> *</code></td>
<td>Out parameter.  On success, <code>*rval</code> receives the value from the last executed expression statement processed in the script.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_EvaluateScriptForPrincipals</code> compiles and executes a script associated with a JS object, <code>obj</code>.  <code>JS_EvaluateUCScriptForPrincipals</code> is the Unicode version of the function.
</p><p>On successful completion, <code>*rval</code> receives the value from the last executed expression statement processed in the script.
</p><p><code>principals</code> is a pointer to the <code><a href="en/JSPrincipals">JSPrincipals</a></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 used in 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>If a secure script compiles and executes successfully, <code>JS_EvaluateScriptForPrincipals</code> returns <code>JS_TRUE</code>. Otherwise it returns <code>JS_FALSE</code>, and the value left in <code>*rval</code> is undefined.
</p>
<h2 name="See_Also"> See Also </h2>
<p>{{template.LXRSearch("ident", "i", "JS_EvaluateScriptForPrincipals")}}<br>
{{template.LXRSearch("ident", "i", "JS_EvaluateUCScriptForPrincipals")}}
</p><p><a href="en/JS_CompileFile">JS_CompileFile</a>,
<a href="en/JS_CompileScriptForPrincipals">JS_CompileScriptForPrincipals</a>,
<a href="en/JS_EvaluateScript">JS_EvaluateScript</a>
</p>
Revert to this revision