JS_NewDoubleValue

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_NewDoubleValue
  • Revision title: JS_NewDoubleValue
  • Revision id: 376347
  • Created:
  • Creator: scavenger
  • Is current revision? No
  • Comment

Revision Content

{{ obsolete_header("jsapi17") }}

Use JS_NumberValue instead.

Syntax

JSBool JS_NewDoubleValue(JSContext *cx, jsdouble d, jsval *rval);
Name Type Description
cx JSContext * The context in which to create the new number. {{ Jsapi-requires-request() }}
d jsdouble The numeric value to convert. This must not be a value that could fit in an integer jsval (see INT_FITS_IN_JSVAL).
rval jsval * Out parameter. On success, *rval receives a JavaScript number with the value d.

Description

JS_NewDoubleValue creates a floating-point jsval.

{{ Warning("The argument d must not be a value that could fit in an integer jsval. If it is, JS_NewDoubleValue creates a bad jsval that might behave as desired in some cases but not others.") }}

The result is subject to garbage collection until you protect against it using a local root, an object property, or the JS_AddRoot function. This can be avoided by using the address of a rooted variable as rval.

On success, JS_NewDoubleValue stores a numeric jsval in *rval and returns JS_TRUE. Otherwise it returns JS_FALSE and the value left in *rval is unspecified.

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

Revision Source

<p>{{ obsolete_header("jsapi17") }}</p>
<p>Use <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NumberValue" title="en/JS_NumberValue">JS_NumberValue</a></code> instead.</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_NewDoubleValue</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/en/SpiderMonkey/JSAPI_Reference/jsdouble" title="en/jsdouble">jsdouble</a> d, <a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a> *rval);
</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>The context in which to create the new number. {{ Jsapi-requires-request() }}</td>
    </tr>
    <tr>
      <td><code>d</code></td>
      <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/jsdouble" title="en/jsdouble">jsdouble</a></code></td>
      <td>The numeric value to convert. This must not be a value that could fit in an integer <code>jsval</code> (see <code><a href="/en/SpiderMonkey/JSAPI_Reference/INT_FITS_IN_JSVAL" title="en/INT_FITS_IN_JSVAL">INT_FITS_IN_JSVAL</a></code>).</td>
    </tr>
    <tr>
      <td><code>rval</code></td>
      <td><code><a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a> *</code></td>
      <td>Out parameter. On success, <code>*rval</code> receives a JavaScript number with the value <code>d</code>.</td>
    </tr>
  </tbody>
</table>
<h2 id="Description" name="Description">Description</h2>
<p><strong><code>JS_NewDoubleValue</code></strong> creates a floating-point <code><a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a></code>.</p>
<p>{{ Warning("The argument <code>d</code> must not be a value that could fit in an integer <code>jsval</code>. If it is, <code>JS_NewDoubleValue</code> creates a bad <code>jsval</code> that might behave as desired in some cases but not others.") }}</p>
<p>The result is subject to garbage collection until you protect against it using a local root, an object property, or the <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_AddRoot" title="en/JS_AddRoot">JS_AddRoot</a></code> function. This can be avoided by using the address of a rooted variable as <code>rval</code>.</p>
<p>On success, <code>JS_NewDoubleValue</code> stores a numeric <code>jsval</code> in <code>*rval</code> and returns <code>JS_TRUE</code>. Otherwise it returns <code>JS_FALSE</code> and the value left in <code>*rval</code> is unspecified.</p>
<p>{{ LXRSearch("ident", "i", "JS_NewDoubleValue") }}</p>
Revert to this revision