JS_NewDouble

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_NewDouble
  • Revision title: JS_NewDouble
  • Revision id: 69175
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment 1 words added, 1 words removed

Revision Content

{{ Deprecated_header() }}

Deprecated in SpiderMonkey 1.8. Use JS_NewNumberValue instead.

Syntax

jsdouble * JS_NewDouble(JSContext *cx, jsdouble d);
Name Type Description
cx JSContext * The context in which to create the new number. {{ Jsapi-requires-request() }}
d jsdouble The number to copy.

Description

JS_NewDouble allocates a copy of the number d on the JavaScript garbage collection heap. This function is not very useful. To convert a jsdouble to a jsval, use JS_NewNumberValue instead.

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

The new jsdouble is subject to garbage collection until you protect it using a local root, an object property, or the JS_AddRoot function.

On success, JS_NewDouble returns a pointer to the new number. Otherwise it returns NULL.

The application must treat the returned pointer as read-only. Modifying a jsdouble allocated with this function can cause undefined behavior.

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

Revision Source

 <p>{{ Deprecated_header() }}</p>
<p>Deprecated in SpiderMonkey 1.8. Use <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewNumberValue" title="en/JS_NewNumberValue">JS_NewNumberValue</a></code> instead.</p>
<h2 name="Syntax">Syntax</h2>
<pre class="eval"><a href="/en/SpiderMonkey/JSAPI_Reference/jsdouble" title="en/jsdouble">jsdouble</a> * <strong>JS_NewDouble</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);
</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 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 number to copy.</td> </tr> </tbody>
</table>
<h2 name="Description">Description</h2>
<p><code>JS_NewDouble</code> allocates a copy of the number <code>d</code> on the JavaScript garbage collection heap. This function is not very useful. To convert a <code>jsdouble</code> to a <code><a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a></code>, use <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewNumberValue" title="en/JS_NewNumberValue">JS_NewNumberValue</a></code> instead.</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_NewDouble</code> creates a bad <code>jsdouble</code> that might behave as desired in some cases but not others.") }}</p>
<p>The new <code>jsdouble</code> is subject to garbage collection until you protect 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.</p>
<p>On success, <code>JS_NewDouble</code> returns a pointer to the new number. Otherwise it returns <code>NULL</code>.</p>
<p>The application must treat the returned pointer as read-only. Modifying a <code>jsdouble</code> allocated with this function can cause undefined behavior.</p>
<p>{{ LXRSearch("ident", "i", "JS_NewDouble") }}</p>
Revert to this revision