JS NewGlobalObject

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_NewGlobalObject
  • Revision title: JS NewGlobalObject
  • Revision id: 113879
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment 1 words added

Revision Content

Create a new JavaScript object for use as a global object.

Syntax

JSObject * JS_NewGlobalObject(JSContext *cx, JSClass *clasp);
Name Type Description
cx JSContext * The context in which to create the new global object. {{ Jsapi-requires-request() }}
clasp JSClass *

The class to use for the new global object.

clasp->flags must have the JSCLASS_GLOBAL_FLAGS bits set.

The caller must ensure that the JSClass remains alive throughout the lifetime of the new object, including the garbage collection cycle that finally frees it. The usual way to do this is to make JSClasses global or static.

Description

JS_NewGlobalObject creates a new global object based on the specified class.

The new object has no parent. It initially has no prototype either, since it is typically the first object created; call JS_InitStandardClasses to create all the standard objects, including Object.prototype, and set the global object's prototype.

The constructor clasp->construct is not called.

On success, JS_NewGlobalObject returns a pointer to the new object. Otherwise it returns NULL.

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

Revision Source

<p>Create a new JavaScript object for use as a global object.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="eval"><a href="/en/SpiderMonkey/JSAPI_Reference/JSObject" title="en/JSObject">JSObject</a> * <strong>JS_NewGlobalObject</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass" title="en/JSClass">JSClass</a> *clasp);
</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 create the new global object. {{ Jsapi-requires-request() }}</td> </tr> <tr> <td><code>clasp</code></td> <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass" title="en/JSClass">JSClass</a> *</code></td> <td> <p>The class to use for the new global object.</p> <p><code>clasp-&gt;flags</code> must have the <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGlobalObject" title="en/SpiderMonkey/JSAPI Reference/JS SetGlobalObject"><code>JSCLASS_GLOBAL_FLAGS</code></a> bits set.</p> The caller must ensure that the <code>JSClass</code> remains alive throughout the lifetime of the new object, including the garbage collection cycle that finally frees it. The usual way to do this is to make <code>JSClass</code>es global or <code>static</code>.</td> </tr> </tbody>
</table>
<h2 id="Description" name="Description">Description</h2>
<p><strong><code>JS_NewGlobalObject</code></strong> creates a new global object based on the specified class.</p>
<p>The new object has no <a class="internal" href="/en/SpiderMonkey/JSAPI_Reference/JS_GetParent" title="En/SpiderMonkey/JSAPI Reference/JS GetParent">parent</a>. It initially has no prototype either, since it is typically the first object created; call <a href="/en/SpiderMonkey/JSAPI_Reference/JS_InitStandardClasses" title="en/SpiderMonkey/JSAPI Reference/JS InitStandardClasses"><code>JS_InitStandardClasses</code></a> to create all the standard objects, including <code>Object.prototype</code>, and set the global object's prototype.</p>
<p>The constructor <code><a href="/en/JSClass.construct" title="en/JSClass.construct">clasp-&gt;construct</a></code> is not called.</p>
<p>On success, <code>JS_NewGlobalObject</code> returns a pointer to the new object. Otherwise it returns <code>NULL</code>.</p>
<p>{{ LXRSearch("ident", "i", "JS_NewGlobalObject") }}</p>
Revert to this revision