JS_InitStandardClasses

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_InitStandardClasses
  • Revision title: JS_InitStandardClasses
  • Revision id: 287479
  • Created:
  • Creator: Jorend
  • Is current revision? Yes
  • Comment 16 words added, 11 words removed

Revision Content

Initializes general JS function and object classes, and the built-in object classes used in most scripts.

Syntax

JSBool JS_InitStandardClasses(JSContext *cx, JSObject *obj);
Name Type Description
cx JSContext * Pointer to the executable script context for which to initialize JS function and object classes. {{ Jsapi-requires-request() }}
obj JSObject * The global object to initialize. This object must be of a JSClass that has the JSCLASS_GLOBAL_FLAGS bits set.

Description

JS_InitStandardClasses initializes the built-in JavaScript global properties. These include all the standard ECMAScript global properties defined in {{ Es3_spec(15.1) }}:

Array, Boolean, Date, decodeURI, decodeURIComponent, encodeURI, encodeURIComponent, Error, eval, EvalError, Function, Infinity, isNaN, isFinite, Math, NaN, Number, Object, parseInt, parseFloat, RangeError, ReferenceError, RegExp, String, SyntaxError, TypeError, undefined, and URIError

as well as a few SpiderMonkey-specific globals, depending on compile-time options:

escape, unescape, uneval, InternalError, Script, XML, Namespace, QName, File, Generator, Iterator, and StopIteration, as of SpiderMonkey 1.7.

These global objects, functions, constructors, and constants are created as properties of obj. As a side effect, JS_InitStandardClasses establishes obj as the global object for cx, if one is not already established. This means that scripts executed in cx will see the properties of obj as global variables. See JS_SetGlobalObject for details.

obj must be of a JSClass that has the JSCLASS_GLOBAL_FLAGS flag.

JS_InitStandardClasses returns JS_TRUE on success, and JS_FALSE if an error occurs.

To initialize custom classes, use JS_InitClass.

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

Revision Source

<p>Initializes general JS function and object classes, and the built-in object classes used in most scripts.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="eval"><a href="/En/SpiderMonkey/JSAPI_Reference/JSBool" title="en/JSBool">JSBool</a> <strong>JS_InitStandardClasses</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);
</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>Pointer to the executable script context for which to initialize JS function and object classes. {{ 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>The global object to initialize. This object must be of a <code>JSClass</code> that has the <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/SpiderMonkey/JSAPI Reference/JSClass.flags"><code>JSCLASS_GLOBAL_FLAGS</code></a> bits set.</td> </tr> </tbody>
</table>
<h2 id="Description" name="Description">Description</h2>
<p><code>JS_InitStandardClasses</code> initializes the built-in JavaScript global properties. These include all the standard ECMAScript global properties defined in {{ Es3_spec(15.1) }}:</p>
<dl> <dd><code>Array</code>, <code>Boolean</code>, <code>Date</code>, <code>decodeURI</code>, <code>decodeURIComponent</code>, <code>encodeURI</code>, <code>encodeURIComponent</code>, <code>Error</code>, <code>eval</code>, <code>EvalError</code>, <code>Function</code>, <code>Infinity</code>, <code>isNaN</code>, <code>isFinite</code>, <code>Math</code>, <code>NaN</code>, <code>Number</code>, <code>Object</code>, <code>parseInt</code>, <code>parseFloat</code>, <code>RangeError</code>, <code>ReferenceError</code>, <code>RegExp</code>, <code>String</code>, <code>SyntaxError</code>, <code>TypeError</code>, <code>undefined</code>, and <code>URIError</code></dd>
</dl>
<p>as well as a few SpiderMonkey-specific globals, depending on compile-time options:</p>
<dl> <dd><code>escape</code>, <code>unescape</code>, <code>uneval</code>, <code>InternalError</code>, <code>Script</code>, <code>XML</code>, <code>Namespace</code>, <code>QName</code>, <code>File</code>, <code>Generator</code>, <code>Iterator</code>, and <code>StopIteration</code>, as of SpiderMonkey 1.7.</dd>
</dl>
<p>These global objects, functions, constructors, and constants are created as properties of <code>obj</code>. As a side effect, <code>JS_InitStandardClasses</code> establishes <code>obj</code> as the global object for <code>cx</code>, if one is not already established. This means that scripts executed in <code>cx</code> will see the properties of <code>obj</code> as global variables. See <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGlobalObject" title="en/JS_SetGlobalObject">JS_SetGlobalObject</a></code> for details.</p>
<p><code>obj</code> must be of a <code>JSClass</code> that has the <code><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSCLASS_GLOBAL_FLAGS</a></code> flag.</p>
<p><code>JS_InitStandardClasses</code> returns <code>JS_TRUE</code> on success, and <code>JS_FALSE</code> if an error occurs.</p>
<p>To initialize custom classes, use <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_InitClass" title="en/JS_InitClass">JS_InitClass</a></code>.</p>
<p>{{ LXRSearch("ident", "i", "JS_InitStandardClasses") }}</p>
Revert to this revision