JS_ValueToBoolean

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_ValueToBoolean
  • Revision title: JS_ValueToBoolean
  • Revision id: 287477
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment 14 words removed

Revision Content

Convert any JavaScript value to a boolean value.

Syntax

JSBool JS_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp);
Name Type Description
cx JSContext * The context in which to perform the conversion. {{ Jsapi-requires-request() }}
v jsval The value to convert.
bp JSBool * Out parameter. On success, *bp receives the converted boolean value.

Description

JS_ValueToBoolean converts a specified JavaScript value, v, to a boolean value. It implements the ToBoolean operator specified in {{ Es3_spec(9.2) }}. On success, JS_ValueToBoolean stores the converted value in *bp and returns JS_TRUE. On error or exception, it returns JS_FALSE, and the value left in *bp is undefined.

For versions greater than JSVERSION_1_2, all objects convert to JS_TRUE, even Boolean wrapper objects like the one produced by new Boolean(false). This is the behavior specified in {{ Es3_spec(9.2) }}. See related discussion on Google Groups.

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

Revision Source

<p>Convert any JavaScript value to a boolean value.
</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_ValueToBoolean</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a> v, <a href="/En/SpiderMonkey/JSAPI_Reference/JSBool" title="en/JSBool">JSBool</a> *bp);
</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> *</code></td>
<td>The context in which to perform the conversion.
{{ Jsapi-requires-request() }}</td>
</tr>
<tr>
<td><code>v</code></td>
<td><code><a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a></code></td>
<td>The value to convert.</td>
</tr>
<tr>
<td><code>bp</code></td>
<td><code><a href="/En/SpiderMonkey/JSAPI_Reference/JSBool" title="en/JSBool">JSBool</a> *</code></td>
<td>Out parameter. On success, <code>*bp</code> receives the converted boolean value.</td>
</tr>
</tbody></table>
<h2 id="Description" name="Description"> Description </h2>
<p><code>JS_ValueToBoolean</code> converts a specified JavaScript value, <code>v</code>, to a boolean value. It implements the ToBoolean operator specified in {{ Es3_spec(9.2) }}. On success, <code>JS_ValueToBoolean</code> stores the converted value in <code>*bp</code> and returns <code>JS_TRUE</code>. On error or exception, it returns <code>JS_FALSE</code>, and the value left in <code>*bp</code> is undefined. </p><p>For versions greater than <code>JSVERSION_1_2</code>, all objects convert to <code>JS_TRUE</code>, even <code>Boolean</code> wrapper objects like the one produced by <code>new Boolean(false)</code>. This is the behavior specified in {{ Es3_spec(9.2) }}. See related discussion on <a class="external" href="http://groups.google.com/group/netscape.public.mozilla.jseng/browse_thread/thread/13de1825f1935156/5c1901b7d4b31c4f">Google Groups</a>.
</p><p>{{ LXRSearch("ident", "i", "JS_ValueToBoolean") }}
</p>
Revert to this revision