JS_HasArrayLength

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_HasArrayLength
  • Revision title: JS_HasArrayLength
  • Revision id: 312741
  • Created:
  • Creator: tschneidereit
  • Is current revision? Yes
  • Comment

Revision Content

{{ obsolete_header("jsapi8") }}

Determines if an object has an array length property.

Syntax

JSBool JS_HasArrayLength(JSContext *cx, JSObject *obj,
    jsuint *lengthp);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. {{ Jsapi-requires-request() }}
obj JSObject * Array object to get the length of.
lengthp jsuint * Out parameter. On success, *lengthp receives the length of the array.

Description

JS_HasArrayLength determines if an object, obj, has a length property. If the property exists, JS_HasArrayLength stores the current value of the property in *lengthp.

On success, JS_HasArrayLength returns JS_TRUE, and *lengthp receives the current value of the length property. On failure, JS_HasArrayLength returns JS_FALSE, and the value left in *lengthp is undefined.

This function differs from JS_GetArrayLength in the treatment of errors and unusual cases, like when an object's length is negative or not a number. This function may return JS_FALSE without having reported any error or exception.

See Also

{{ LXRSearch("ident", "i", "JS_HasArrayLength") }}

JS_DefineElement, JS_DeleteElement, JS_GetArrayLength, JS_GetElement, JS_IsArrayObject, JS_LookupElement, JS_NewArrayObject, JS_SetArrayLength, JS_SetElement

Revision Source

<p>{{ obsolete_header("jsapi8") }}</p>
<p>Determines if an object has an array length property.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="eval">
<a href="/En/SpiderMonkey/JSAPI_Reference/JSBool" title="en/JSBool">JSBool</a> <strong>JS_HasArrayLength</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 href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">jsuint</a> *lengthp);
</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/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a>&nbsp;*</code></td>
      <td>Pointer to a JS context from which to derive runtime information. {{ 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>Array object to get the length of.</td>
    </tr>
    <tr>
      <td><code>lengthp</code></td>
      <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">jsuint</a> *</code></td>
      <td>Out parameter. On success, <code>*lengthp</code> receives the length of the array.</td>
    </tr>
  </tbody>
</table>
<h2 id="Description" name="Description">Description</h2>
<p><code>JS_HasArrayLength</code> determines if an object, <code>obj</code>, has a <code>length</code> property. If the property exists, <code>JS_HasArrayLength</code> stores the current value of the property in <code>*lengthp</code>.</p>
<p>On success, <code>JS_HasArrayLength</code> returns <code>JS_TRUE</code>, and <code>*lengthp</code> receives the current value of the <code>length</code> property. On failure, <code>JS_HasArrayLength</code> returns <code>JS_FALSE</code>, and the value left in <code>*lengthp</code> is undefined.</p>
<p>This function differs from <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetArrayLength" title="en/JS_GetArrayLength">JS_GetArrayLength</a></code> in the treatment of errors and unusual cases, like when an object's <code>length</code> is negative or not a number. This function may return <code>JS_FALSE</code> without having reported any error or exception.</p>
<h2 id="See_Also" name="See_Also">See Also</h2>
<p>{{ LXRSearch("ident", "i", "JS_HasArrayLength") }}</p>
<p><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DefineElement" title="en/JS_DefineElement">JS_DefineElement</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_DeleteElement" title="en/JS_DeleteElement">JS_DeleteElement</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetArrayLength" title="en/JS_GetArrayLength">JS_GetArrayLength</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetElement" title="en/JS_GetElement">JS_GetElement</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_IsArrayObject" title="en/JS_IsArrayObject">JS_IsArrayObject</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_LookupElement" title="en/JS_LookupElement">JS_LookupElement</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewArrayObject" title="en/JS_NewArrayObject">JS_NewArrayObject</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetArrayLength" title="en/JS_SetArrayLength">JS_SetArrayLength</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetElement" title="en/JS_SetElement">JS_SetElement</a></p>
Revert to this revision