JSObjectOps.getProperty

  • Revision slug: SpiderMonkey/JSAPI_Reference/JSObjectOps.getProperty
  • Revision title: JSObjectOps.getProperty
  • Revision id: 139447
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment /* Syntax */

Revision Content

{{ Jsapi_ref_header("JSObjectOps.getProperty") }} {{ JSObjectOps_warning() }}

JSObjectOps.getProperty, setProperty, and deleteProperty are high-level callbacks that implement object property accesses.

Each of these callbacks is responsible for everything involved with an individual property access operation, including: any locking necessary for thread safety; security checks; finding the property, including walking the prototype chain if needed; calling the lower-level JSClass hooks; calling getters or setters; and actually getting, setting, or deleting the property once it is found.

Contrast JSClass.getProperty, JSClass.setProperty, and JSClass.delProperty, which are hooks called during property accesses and don't have to implement any of that.

Syntax

typedef JSBool (*JSPropertyIdOp)(
    JSContext *cx, JSObject *obj, jsid id, jsval *vp);
Name Type Description
cx JSContext * Pointer to the JS context in which the property access is happening.
obj JSObject * The object to be accessed.
id jsid The name or index of the property to access.
vp jsval * In/out parameter. See the Description section below.

Description

Get, set, or delete obj{{ mediawiki.external('id') }}, returning JS_FALSE on error or exception, JS_TRUE on success. If getting or setting, the new value is returned in *vp on success.

If deleting without error, *vp will be JSVAL_FALSE if obj{{ mediawiki.external('id') }} is permanent, and JSVAL_TRUE if id named a direct property of obj that was in fact deleted, or if id names no direct property of obj (id could name a property of a prototype, or no property in obj or its prototype chain). This reflects the quirky behavior of delete as specified in the ECMAScript 3 standard, §11.4.1 and §8.6.2.5.

Revision Source

<p>{{ Jsapi_ref_header("JSObjectOps.getProperty") }}
{{ JSObjectOps_warning() }}
</p><p><b><code><a href="en/JSObjectOps">JSObjectOps</a>.getProperty</code></b>, <b><code>setProperty</code></b>, and <b><code>deleteProperty</code></b> are high-level callbacks that implement object property accesses.
</p><p>Each of these callbacks is responsible for everything involved with an individual property access operation, including: any locking necessary for thread safety; security checks; finding the property, including walking the prototype chain if needed; calling the lower-level <code>JSClass</code> hooks; calling getters or setters; and actually getting, setting, or deleting the property once it is found.
</p><p>Contrast <code><a href="en/JSClass.getProperty">JSClass.getProperty</a></code>, <code><a href="en/JSClass.setProperty">JSClass.setProperty</a></code>, and <code><a href="en/JSClass.delProperty">JSClass.delProperty</a></code>, which are <i>hooks</i> called during property accesses and don't have to implement any of that.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval">typedef JSBool (*<b>JSPropertyIdOp</b>)(
    <a href="en/JSContext">JSContext</a> *cx, <a href="en/JSObject">JSObject</a> *obj, <a href="en/Jsid">jsid</a> id, <a href="en/Jsval">jsval</a> *vp);
</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 property access is happening.</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code><a href="en/JSObject">JSObject</a> *</code></td>
<td>The object to be accessed.</td>
</tr>
<tr>
<td><code>id</code></td>
<td><code><a href="en/Jsid">jsid</a></code></td>
<td>The name or index of the property to access.</td>
</tr>
<tr>
<td><code>vp</code></td>
<td><code><a href="en/Jsval">jsval</a> *</code></td>
<td>In/out parameter. See the Description section below.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p>Get, set, or delete <code>obj{{ mediawiki.external('id') }}</code>, returning <code>JS_FALSE</code> on error or exception, <code>JS_TRUE</code> on success. If getting or setting, the new value is returned in <code>*vp</code> on success.
</p><p>If deleting without error, <code>*vp</code> will be <code>JSVAL_FALSE</code> if <code>obj{{ mediawiki.external('id') }}</code> is permanent, and <code>JSVAL_TRUE</code> if <code>id</code> named a direct property of <code>obj</code> that was in fact deleted, or if <code>id</code> names no direct property of <code>obj</code> (<code>id</code> could name a property of a prototype, or no property in <code>obj</code> or its prototype chain). This reflects the quirky behavior of <code>delete</code> as specified in the ECMAScript 3 standard, <a class="external" href="http://bclary.com/2004/11/07/#a-11.4.1">§11.4.1</a> and <a class="external" href="http://bclary.com/2004/11/07/#a-8.6.2.5">§8.6.2.5</a>.
</p>
Revert to this revision