|
|
@ -17,7 +17,7 @@ |
|
|
|
</table> |
|
|
|
</div> |
|
|
|
|
|
|
|
<h2>Memory allocations</h2> |
|
|
|
<h2 id="type-memory-allocations">Memory allocations</h2> |
|
|
|
|
|
|
|
<p>The following stack types involve additional heap allocations:</p> |
|
|
|
|
|
|
@ -37,7 +37,7 @@ |
|
|
|
type in Ecmascript, they are a heap allocated type from a memory allocation |
|
|
|
viewpoint.</p> |
|
|
|
|
|
|
|
<h2>Pointer stability</h2> |
|
|
|
<h2 id="type-pointer-stability">Pointer stability</h2> |
|
|
|
|
|
|
|
<p>Heap objects allocated by Duktape have stable pointers: the objects are |
|
|
|
not relocated in memory while they are reachable from a garbage collection |
|
|
@ -65,7 +65,7 @@ area across a buffer resize, and it's probably best not to hold a pointer |
|
|
|
after a Duktape/C function returns (how would you reliably know when the |
|
|
|
buffer is resized?).</p> |
|
|
|
|
|
|
|
<h2>Type masks</h2> |
|
|
|
<h2 id="type-masks">Type masks</h2> |
|
|
|
|
|
|
|
<p>Type masks allows calling code to easily check whether a type belongs to |
|
|
|
a certain type set. For instance, to check that a certain stack value is |
|
|
@ -105,12 +105,12 @@ if (t == DUK_TYPE_NUMBER || t == DUK_TYPE_STRING || t == DUK_TYPE_OBJECT) { |
|
|
|
} |
|
|
|
</pre> |
|
|
|
|
|
|
|
<h2>None</h2> |
|
|
|
<h2 id="type-none">None</h2> |
|
|
|
|
|
|
|
<p>The <b>none</b> type is not actually a type but is used in the API to |
|
|
|
indicate that a value does not exist, a stack index is invalid, etc.</p> |
|
|
|
|
|
|
|
<h2>Undefined</h2> |
|
|
|
<h2 id="type-undefined">Undefined</h2> |
|
|
|
|
|
|
|
<p>The <b>undefined</b> type maps to Ecmascript <code>undefined</code>, which is |
|
|
|
distinguished from a <code>null</code>.</p> |
|
|
@ -118,11 +118,11 @@ distinguished from a <code>null</code>.</p> |
|
|
|
<p>Values read from outside the active value stack range read back as |
|
|
|
<b>undefined</b>.</p> |
|
|
|
|
|
|
|
<h2>Null</h2> |
|
|
|
<h2 id="type-null">Null</h2> |
|
|
|
|
|
|
|
<p>The <b>null</b> type maps to Ecmascript <code>null</code>.</p> |
|
|
|
|
|
|
|
<h2>Boolean</h2> |
|
|
|
<h2 id="type-boolean">Boolean</h2> |
|
|
|
|
|
|
|
<p>The <b>boolean</b> type is represented in the C API as an integer: zero for false, |
|
|
|
and non-zero for true.</p> |
|
|
@ -151,7 +151,7 @@ int bitmask = (duk_get_boolean(ctx, -3) ? (1 << 2) : 0) | |
|
|
|
(duk_get_boolean(ctx, -1) ? 1 : 0); |
|
|
|
</pre> |
|
|
|
|
|
|
|
<h2>Number</h2> |
|
|
|
<h2 id="type-number">Number</h2> |
|
|
|
|
|
|
|
<p>The <b>number</b> type is an IEEE double, including +/- Infinity and NaN values. |
|
|
|
Zero sign is also preserved. An IEEE double represents all integers up to 53 bits |
|
|
@ -163,7 +163,7 @@ packed values), NaN values in the Duktape API are normalized. Concretely, if yo |
|
|
|
push a certain NaN value to the value stack, another (normalized) NaN value may |
|
|
|
come out. Don't rely on NaNs preserving their exact form.</p> |
|
|
|
|
|
|
|
<h2>String</h2> |
|
|
|
<h2 id="type-string">String</h2> |
|
|
|
|
|
|
|
<p>The <b>string</b> type is a raw byte sequence of a certain length which may |
|
|
|
contain internal NUL (0x00) values. Strings are always automatically NUL |
|
|
@ -247,7 +247,7 @@ continuation bytes are marked with "C" (indicating the bit sequence 10xxxxxx):</ |
|
|
|
the leading byte will be <code>0xFE</code> which conflicts with Unicode byte order |
|
|
|
marker encoding. This is not a practical concern in Duktape's internal use.</p> |
|
|
|
|
|
|
|
<h2>Object</h2> |
|
|
|
<h2 id="type-object">Object</h2> |
|
|
|
|
|
|
|
<p>The <b>object</b> type includes Ecmascript objects and arrays, functions, and |
|
|
|
threads (coroutines). In other words, anything with properties is an object. |
|
|
@ -256,7 +256,7 @@ Properties are key-value pairs with a string key and an arbitrary value |
|
|
|
|
|
|
|
<p>Objects may participate in garbage collection finalization.</p> |
|
|
|
|
|
|
|
<h2>Buffer</h2> |
|
|
|
<h2 id="type-buffer">Buffer</h2> |
|
|
|
|
|
|
|
<p>The <b>buffer</b> type is a raw buffer for user data of either fixed or dynamic |
|
|
|
size. The size of a fixed buffer is given at its creation, and fixed buffers |
|
|
@ -289,21 +289,22 @@ property is read-only at the moment (so you can't resize a string by assigning |
|
|
|
to the length property). These properties are available for both plain buffer |
|
|
|
values and buffer object values.</p> |
|
|
|
|
|
|
|
<div class="note"> |
|
|
|
Because the value written to a buffer index is number coerced, assigning |
|
|
|
<p>A few notes:</p> |
|
|
|
<ul> |
|
|
|
<li>Because the value written to a buffer index is number coerced, assigning |
|
|
|
a one-character value does not work as often expected. For instance, |
|
|
|
<code>buf[123] = 'x'</code> causes zero to be written to the buffer, as |
|
|
|
ToNumber('x') = 0. For clarity, you should only assign number values, |
|
|
|
e.g. <code>buf[123] = 0x78</code>. |
|
|
|
</div> |
|
|
|
|
|
|
|
<div class="note"> |
|
|
|
There is a fast path for reading and writing numeric indices of plain buffer |
|
|
|
e.g. <code>buf[123] = 0x78</code>.</li> |
|
|
|
<li>There is a fast path for reading and writing numeric indices of plain buffer |
|
|
|
values, e.g. <code>x = buf[123]</code> or <code>buf[123] = x</code>. This |
|
|
|
fast path is not active when the base value is a Buffer object. |
|
|
|
</div> |
|
|
|
fast path is not active when the base value is a Buffer object.</li> |
|
|
|
<li>Buffer virtual properties are not currently implemented in |
|
|
|
<code>defineProperty()</code>, so you can't write to buffer indices or |
|
|
|
buffer <code>length</code> with <code>defineProperty()</code> now.</li> |
|
|
|
</ul> |
|
|
|
|
|
|
|
<h2>Pointer</h2> |
|
|
|
<h2 id="type-pointer">Pointer</h2> |
|
|
|
|
|
|
|
<p>The <b>pointer</b> type is a raw, uninterpreted C pointer, essentially |
|
|
|
a <code>void *</code>. Pointers can be used to point to native objects (memory |
|
|
|