JSObjectOps.newObjectMap

  • Revision slug: SpiderMonkey/JSAPI_Reference/JSObjectOps.newObjectMap
  • Revision title: JSObjectOps.newObjectMap
  • Revision id: 173473
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment fmt

Revision Content

{{template.Jsapi_ref_header("JSObjectOps.newObjectMap")}}

The JSObjectOps.newObjectMap callback is called whenever a new object is created. It creates a JSObjectMap that completely controls the new object's behavior.

Syntax

typedef JSObjectMap * (*JSNewObjectMapOp)(JSContext *cx, jsrefcount nrefs,
    JSObjectOps *ops, JSClass *clasp, JSObject *obj);
Name Type Description
cx JSContext * Pointer to the JS context in which the new object is being created.
nrefs jsrefcount The initial reference count for the new JSObjectMap.
ops JSObjectOps * The ops for the new JSObjectMap.
clasp JSClass * The JSClass of the new object.
obj JSObject * The new object.

Description

Note: The JSAPI does not expose the data structures that would be necessary to develop new JSObjectMap subclasses, so applications must leave the JSObjectOps.newObjectMap slot NULL.

Create a new subclass of JSObjectMap (see {{template.Source("js/src/jsobj.h", "jsobj.h")}}), with the nrefs and ops members initialized from the same-named parameters, and with the nslots and freeslot members initialized according to ops and clasp. Return null on error, non-null on success.

JSObjectMaps are reference-counted by generic code in the engine. Usually, the nrefs parameter to JSObjectOps.newObjectMap will be 1, to count the ref returned to the caller on success. After a successful construction, some number of js_HoldObjectMap and js_DropObjectMap calls ensue. When nrefs reaches 0 due to a js_DropObjectMap call, JSObjectOps.destroyObjectMap will be called to dispose of the map.

Revision Source

<p>{{template.Jsapi_ref_header("JSObjectOps.newObjectMap")}}
</p><p>The <b><code><a href="en/JSObjectOps">JSObjectOps</a>.newObjectMap</code></b> callback is called whenever a new object is created.  It creates a <code><a href="en/JSObjectMap">JSObjectMap</a></code> that completely controls the new object's behavior.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval">typedef JSObjectMap * (*<b>JSNewObjectMapOp</b>)(JSContext *cx, jsrefcount nrefs,
    JSObjectOps *ops, JSClass *clasp, JSObject *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/JSContext">JSContext</a> *</code></td>
<td>Pointer to the JS context in which the new object is being created.</td>
</tr>
<tr>
<td><code>nrefs</code></td>
<td><code><a href="en/Jsrefcount">jsrefcount</a></code></td>
<td>The initial reference count for the new <code>JSObjectMap</code>.</td>
</tr>
<tr>
<td><code>ops</code></td>
<td><code><a href="en/JSObjectOps">JSObjectOps</a> *</code></td>
<td>The <code>ops</code> for the new <code>JSObjectMap</code>.</td>
</tr>
<tr>
<td><code>clasp</code></td>
<td><code><a href="en/JSClass">JSClass</a> *</code></td>
<td>The <code>JSClass</code> of the new object.</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code><a href="en/JSObject">JSObject</a> *</code></td>
<td>The new object.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><b>Note:</b> The JSAPI does not expose the data structures that would be necessary to develop new <code>JSObjectMap</code> subclasses, so applications must leave the <code>JSObjectOps.newObjectMap</code> slot <code>NULL</code>.
</p><p>Create a new subclass of <code><a href="en/JSObjectMap">JSObjectMap</a></code> (see {{template.Source("js/src/jsobj.h", "jsobj.h")}}), with the <code>nrefs</code> and <code>ops</code> members initialized from the same-named parameters, and with the <code>nslots</code> and <code>freeslot</code> members initialized according to <code>ops</code> and <code>clasp</code>.  Return null on error, non-null on success.
</p><p><code>JSObjectMap</code>s are reference-counted by generic code in the engine.  Usually, the <code>nrefs</code> parameter to <code>JSObjectOps.newObjectMap</code> will be <code>1</code>, to count the ref returned to the caller on success.  After a successful construction, some number of <code>js_HoldObjectMap</code> and <code>js_DropObjectMap</code> calls ensue.  When <code>nrefs</code> reaches <code>0</code> due to a <code>js_DropObjectMap</code> call, <code><a href="en/JSObjectOps">JSObjectOps</a>.destroyObjectMap</code> will be called to dispose of the map.
</p>
Revert to this revision