JS_GetPropertyAttrsGetterAndSetter

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttrsGetterAndSetter
  • Revision title: JS_GetPropertyAttrsGetterAndSetter
  • Revision id: 138532
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment 52 words added

Revision Content

Retrieve the attributes, getter, and setter of a specified property.

Syntax

JSBool JS_GetPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
    const char *name, uintN *attrsp, JSBool *foundp,
    JSPropertyOp *getterp, JSPropertyOp *setterp);

JSBool JS_GetUCPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
    const jschar *name, size_t namelen,
    uintN *attrsp, JSBool *foundp,
    JSPropertyOp *getterp, JSPropertyOp *setterp);

JSBool JS_GetPropertyAttrsGetterAndSetterById(JSContext *cx, JSObject *obj,
    jsid id, uintN *attrsp, JSBool *foundp,
    JSPropertyOp *getterp, JSPropertyOp *setterp);

 

Name Type Description
cx JSContext * The context in which to perform the property lookup. {{ Jsapi-requires-request() }}
obj JSObject * Object from which to retrieve property attributes.
name const char * or const jschar * (only in JS_GetPropertyAttrsGetterAndSetter and JS_GetUCPropertyAttrsGetterAndSetter) Name of the property to examine.
namelen size_t (only in JS_GetUCPropertyAttrsGetterAndSetter) The length of name in characters; or (size_t) -1 to indicate that name is null-terminated.
id jsid (only in JS_GetPropertyAttrsGetterAndSetterById) The id of the property to examine.
attrsp uintN * Out parameter. Pointer to the storage area into which to place retrieves attributes.
foundp JSBool * Out parameter. Flag indicating whether or not the specified property was located.
getterp JSPropertyOp * Out parameter. On success, *getterp receives a pointer to the getter function for the specified property.
setterp JSPropertyOp * Out parameter. On success, *setterp receives a pointer to the setter function for the specified property.

Description

See JS_GetPropertyAttributes for details about these functions. The only difference is that on success, these functions also get the getter and setter functions for the property.

The JS_GETTER (or JS_SETTER) attribute indicates that the property's getter (or setter) is a JavaScript function, not a C/C++ function. When this attribute is present, the value stored in getterp (or setterp) does not really point to a C/C++ function; it is a JSObject *, pointing to a JavaScript function, cast to type JSPropertyOp. The application may cast it back to JSObject * (using a C cast or a C++ reinterpret_cast) to access the getter/setter function object. For more information about JavaScript getters and setters, see Defining Getters and Setters.

{{ LXRSearch("ident", "i", "JS_GetPropertyAttrsGetterAndSetter") }}
{{ LXRSearch("ident", "i", "JS_GetUCPropertyAttrsGetterAndSetter") }}

Revision Source

<p>Retrieve the attributes, getter, and setter of a specified property.</p>
<h2 name="Syntax">Syntax</h2>
<pre class="eval"><a href="/En/SpiderMonkey/JSAPI_Reference/JSBool" title="en/JSBool">JSBool</a> <strong>JS_GetPropertyAttrsGetterAndSetter</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,
    const char *name, <a href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">uintN</a> *attrsp, <a href="/En/SpiderMonkey/JSAPI_Reference/JSBool" title="en/JSBool">JSBool</a> *foundp,
    <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.addProperty" title="en/JSClass.addProperty">JSPropertyOp</a> *getterp, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.addProperty" title="en/JSClass.addProperty">JSPropertyOp</a> *setterp);

<a href="/En/SpiderMonkey/JSAPI_Reference/JSBool" title="en/JSBool">JSBool</a> <strong>JS_GetUCPropertyAttrsGetterAndSetter</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,
    const <a href="/en/SpiderMonkey/JSAPI_Reference/jschar" title="en/jschar">jschar</a> *name, size_t namelen,
    <a href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">uintN</a> *attrsp, <a href="/En/SpiderMonkey/JSAPI_Reference/JSBool" title="en/JSBool">JSBool</a> *foundp,
    <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.addProperty" title="en/JSClass.addProperty">JSPropertyOp</a> *getterp, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.addProperty" title="en/JSClass.addProperty">JSPropertyOp</a> *setterp);

<a href="/En/SpiderMonkey/JSAPI_Reference/JSBool" title="en/JSBool">JSBool</a> <strong>JS_GetPropertyAttrsGetterAndSetterById</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,
    <a class="internal" href="/En/SpiderMonkey/JSAPI%20Reference/Jsid" title="En/SpiderMonkey/JSAPI Reference/Jsid">jsid</a> id, <a href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">uintN</a> *attrsp, <a href="/En/SpiderMonkey/JSAPI_Reference/JSBool" title="en/JSBool">JSBool</a> *foundp,
    <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.addProperty" title="en/JSClass.addProperty">JSPropertyOp</a> *getterp, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.addProperty" title="en/JSClass.addProperty">JSPropertyOp</a> *setterp);

</pre>
<p> </p>
<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 perform the property lookup. {{ 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>Object from which to retrieve property attributes.</td> </tr> <tr> <td><code>name</code></td> <td><code>const char *</code> <em>or</em> <code>const <a href="/en/SpiderMonkey/JSAPI_Reference/jschar" title="en/jschar">jschar</a> *</code></td> <td><em>(only in </em><em><code>JS_GetPropertyAttrsGetterAndSetter</code></em><em> and <code>JS_GetUCPropertyAttrsGetterAndSetter</code>) </em>Name of the property to examine.</td> </tr> <tr> <td><code>namelen</code></td> <td><code>size_t</code></td> <td><em>(only in <code>JS_GetUCPropertyAttrsGetterAndSetter</code>)</em> The length of <code>name</code> in characters; or <code>(size_t) -1</code> to indicate that <code>name</code> is null-terminated.</td> </tr> <tr> <td><code>id</code></td> <td><a class="internal" href="/en/SpiderMonkey/JSAPI_Reference/jsid" title="en/SpiderMonkey/JSAPI Reference/jsid"><code>jsid</code></a></td> <td><em>(only in <code>JS_GetPropertyAttrsGetterAndSetterById</code>)</em> The id of the property to examine.</td> </tr> <tr> <td><code>attrsp</code></td> <td><code>uintN *</code></td> <td>Out parameter. Pointer to the storage area into which to place retrieves attributes.</td> </tr> <tr> <td><code>foundp</code></td> <td><code>JSBool *</code></td> <td>Out parameter. Flag indicating whether or not the specified property was located.</td> </tr> <tr> <td><code>getterp</code></td> <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.addProperty" title="en/JSClass.addProperty">JSPropertyOp</a> *</code></td> <td>Out parameter. On success, <code>*getterp</code> receives a pointer to the getter function for the specified property.</td> </tr> <tr> <td><code>setterp</code></td> <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.addProperty" title="en/JSClass.addProperty">JSPropertyOp</a> *</code></td> <td>Out parameter. On success, <code>*setterp</code> receives a pointer to the setter function for the specified property.</td> </tr> </tbody>
</table>
<h2 name="Description">Description</h2>
<p>See <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttributes" title="en/JS_GetPropertyAttributes">JS_GetPropertyAttributes</a></code> for details about these functions. The only difference is that on success, these functions also get the getter and setter functions for the property.</p>
<p>The <code>JS_GETTER</code> (or <code>JS_SETTER</code>) attribute indicates that the property's getter (or setter) is a JavaScript function, not a C/C++ function. When this attribute is present, the value stored in <code>getterp</code> (or <code>setterp</code>) does not really point to a C/C++ function; it is a <code>JSObject *</code>, pointing to a JavaScript function, cast to type <code>JSPropertyOp</code>. The application may cast it back to <code>JSObject *</code> (using a C cast or a C++ <code>reinterpret_cast</code>) to access the getter/setter function object. For more information about JavaScript getters and setters, see <a href="/en/Core_JavaScript_1.5_Guide/Creating_New_Objects/Defining_Getters_and_Setters" title="en/Core_JavaScript_1.5_Guide/Creating_New_Objects/Defining_Getters_and_Setters">Defining Getters and Setters</a>.</p>
<p>{{ LXRSearch("ident", "i", "JS_GetPropertyAttrsGetterAndSetter") }}<br>
{{ LXRSearch("ident", "i", "JS_GetUCPropertyAttrsGetterAndSetter") }}</p>
Revert to this revision