JSClass.checkAccess

  • Revision slug: SpiderMonkey/JSAPI_Reference/JSClass.checkAccess
  • Revision title: JSClass.checkAccess
  • Revision id: 87504
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment style, copy-editing

Revision Content

{{template.Jsapi_ref_header("JSClass.checkAccess")}}

The JSClass.checkAccess callback is called when a script attempts to access an object property. The callback can deny the script access to the property.

Syntax

typedef JSBool (*JSCheckAccessOp)(JSContext *cx, JSObject *obj, jsval id,
    JSAccessMode mode, jsval *vp);
Name Type Description
cx JSContext * The JS context in which the property access attempt is occurring.
obj JSObject * The object whose properties are being accessed.
id jsval The name or index of the property being accessed.
mode JSAccessMode The type of access being checked.
vp jsval * Out parameter. On success, the callback must store the last-got value of the property in *vp.

Description

Check whether obj{{mediawiki.external('id')}} may be accessed per mode, returning JS_FALSE on error/exception, JS_TRUE on success with obj{{mediawiki.external('id')}}'s last-got value in *vp. As for JSPropertyOp, id is either a string or an int jsval.

See JSObjectOps.checkAccess for the JSObjectOps counterpart, which takes a jsid (a tagged int or aligned, unique identifier pointer) rather than a jsval. The native js_ObjectOps.checkAccess simply forwards to the object's clasp->checkAccess, so that both JSClass and JSObjectOps implementors may specialize access checks.

Revision Source

<p>{{template.Jsapi_ref_header("JSClass.checkAccess")}}
</p><p>The <b><code><a href="en/JSClass">JSClass</a>.checkAccess</code></b> callback is called when a script attempts to access an object property.  The callback can deny the script access to the property.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval">typedef JSBool (*<b>JSCheckAccessOp</b>)(JSContext *cx, JSObject *obj, jsval id,
    JSAccessMode mode, jsval *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>The JS context in which the property access attempt is occurring.</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code><a href="en/JSObject">JSObject</a> *</code></td>
<td>The object whose properties are being accessed.</td>
</tr>
<tr>
<td><code>id</code></td>
<td><code><a href="en/Jsval">jsval</a></code></td>
<td>The name or index of the property being accessed.</td>
</tr>
<tr>
<td><code>mode</code></td>
<td><code><a href="en/JSAccessMode">JSAccessMode</a></code></td>
<td>The type of access being checked.</td>
</tr>
<tr>
<td><code>vp</code></td>
<td><code><a href="en/Jsval">jsval</a> *</code></td>
<td>Out parameter.  On success, the callback must store the last-got value of the property in <code>*vp</code>.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p>Check whether <code>obj{{mediawiki.external('id')}}</code> may be accessed per <code>mode</code>, returning <code>JS_FALSE</code> on error/exception, <code>JS_TRUE</code> on success with <code>obj{{mediawiki.external('id')}}</code>'s last-got value in <code>*vp</code>.  As for <code><a href="en/JSPropertyOp">JSPropertyOp</a></code>, <code>id</code> is either a string or an int <code><a href="en/Jsval">jsval</a></code>.
</p><p>See <code><a href="en/JSObjectOps.checkAccess">JSObjectOps.checkAccess</a></code> for the <code><a href="en/JSObjectOps">JSObjectOps</a></code> counterpart, which takes a <code>jsid</code> (a tagged int or aligned, unique identifier pointer) rather than a <code>jsval</code>.  The native <code>js_ObjectOps.checkAccess</code> simply forwards to the object's <code>clasp-&gt;checkAccess</code>, so that both <code>JSClass</code> and <code>JSObjectOps</code> implementors may specialize access checks.
</p>
Revert to this revision