JS_HasProperty

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_HasProperty
  • Revision title: JS_HasProperty
  • Revision id: 138485
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment /* Syntax */ it wouldn't compile

Revision Content

{{template.Jsapiref()}}

Function

Determine whether a JavaScript object has a specified property.

Syntax

JSBool JS_HasProperty(JSContext *cx, JSObject *obj,
   const char *name, JSBool *foundp);

JSBool JS_HasUCProperty(JSContext *cx, JSObject *obj,
   const jschar *name, size_t namelen, JSBool *foundp);


Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. {{wiki.template('Jsapi-requires-request')}}
obj JSObject * Object to search on for the property.
name const char * or const jschar * Name of the property to look up.
namelen size_t (only in JS_HasUCProperty) The length of name in characters, or -1 to indicate that name is null-terminated.
foundp JSBool * Non-null pointer to a variable of type JSBool. On success, JS_HasProperty stores JS_TRUE in this variable if obj has a property with the given name, and JS_FALSE if not.

Description

JS_HasProperty examines a specified JS object, obj, its scope and prototype links, for a property with the specified name. JS_HasUCProperty is the corresponding Unicode API.

If the property exists, this function sets *foundp to JS_TRUE and returns JS_TRUE.

If the object obj has no such property, the function sets *foundp to JS_FALSE and returns JS_TRUE (to indicate that no error occurred).

If an error occurs during the search, the function returns JS_FALSE, and the value of *foundp is undefined.

See Also

Groups Functions
Documents {{template.LXRSearch("ident", "i", "JS_HasProperty", "LXR ID Search")}}
Entries

JS_GetProperty, JS_LookupProperty, JS_PropertyStub, JS_SetProperty

Revision Source

<p> 
{{template.Jsapiref()}}
</p><p><b>Function</b>
</p><p>Determine whether a JavaScript object has a specified property.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval">JSBool <b>JS_HasProperty</b>(JSContext *cx, JSObject *obj,
   const char *name, JSBool *foundp);

JSBool <b>JS_HasUCProperty</b>(JSContext *cx, JSObject *obj,
   const jschar *name, size_t namelen, JSBool *foundp);
</pre>
<p><br>
</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>JSContext *</code></td>
<td>Pointer to a JS context from which to derive runtime information.
{{wiki.template('Jsapi-requires-request')}}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code>JSObject *</code></td>
<td>Object to search on for the property.</td>
</tr>
<tr>
<td><code>name</code></td>
<td><code>const char *</code> <i>or</i> <code>const jschar *</code></td>
<td>Name of the property to look up.</td>
</tr>
<tr>
<td><code>namelen</code></td>
<td><code>size_t</code></td>
<td><i>(only in <code>JS_HasUCProperty</code>)</i> The length of <code>name</code> in characters, or <code>-1</code> to indicate that <code>name</code> is null-terminated.</td>
</tr>
<tr>
<td><code>foundp</code></td>
<td><code>JSBool *</code></td>
<td>Non-null pointer to a variable of type <code>JSBool</code>.  On success, <code>JS_HasProperty</code> stores <code>JS_TRUE</code> in this variable if <code>obj</code> has a property with the given <code>name</code>, and <code>JS_FALSE</code> if not.</td>
</tr>

</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_HasProperty</code> examines a specified JS object, <code>obj</code>, its scope and prototype links, for a property with the specified <code>name</code>.  <code>JS_HasUCProperty</code> is the corresponding Unicode API.
</p><p>If the property exists, this function sets <code>*foundp</code> to <code>JS_TRUE</code> and returns <code>JS_TRUE</code>.
</p><p>If the object <code>obj</code> has no such property, the function sets <code>*foundp</code> to <code>JS_FALSE</code> and returns <code>JS_TRUE</code> (to indicate that no error occurred).
</p><p>If an error occurs during the search, the function returns <code>JS_FALSE</code>, and the value of <code>*foundp</code> is undefined.
</p>
<h2 name="See_Also"> See Also </h2>
<table class="fullwidth-table">
<tbody><tr>
<td>Groups</td>
<td><a href="en/JSAPI_Reference#Functions">Functions</a></td>
</tr>
<tr>
<td>Documents</td>
<td>{{template.LXRSearch("ident", "i", "JS_HasProperty", "LXR ID Search")}}</td>
</tr>
<tr>
<td>Entries</td>
<td>
<p><a href="en/JS_GetProperty">JS_GetProperty</a>,
<a href="en/JS_LookupProperty">JS_LookupProperty</a>,
<a href="en/JS_PropertyStub">JS_PropertyStub</a>,
<a href="en/JS_SetProperty">JS_SetProperty</a>
</p>
</td>
</tr>
</tbody></table>
Revert to this revision