You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

95 lines
5.3 KiB

<h1 id="es6features">Ecmascript E6 features</h1>
<p>This section describes the small set of features Duktape borrows from
<a href="http://www.ecma-international.org/ecma-262/6.0/index.html">Ecmascript E6</a>.
These features are not fully compliant; the intent is to minimize custom features
and to align with the ES6 specification when possible.</p>
<h2 id="es6-const">Const variables</h2>
<p>Duktape has minimal support for
<a href="http://www.ecma-international.org/ecma-262/6.0/#sec-let-and-const-declarations">const</a>
declarations to allow existing code using <code>const</code> to run. However,
<code>const</code> is mostly just an alias for <code>var</code> and currently has
the following non-standard semantics:</p>
<ul>
<li>Unlike <code>var</code> declarations, <code>const</code> declarations are
required to have an initializer.</li>
<li>Const variables are writable. In ES6 <code>const</code> variables are
not writable.</li>
<li>Const variables are function scoped and "hoisted" to the top of the
function like <code>var</code> declarations. In ES6 <code>const</code>
has block scoping like <code>let</code>.</li>
</ul>
<h2 id="es6-proto">Object.setPrototypeOf and Object.prototype.__proto__</h2>
<p><a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.setprototypeof">Object.setPrototypeOf</a>
allows user to set the internal prototype of an object which is not supported in
Ecmascript E5. Ecmascript E6 also provides
<a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.prototype.__proto__">Object.prototype.__proto__</a>,
an accessor property (setter/getter) which provides the same functionality
but is compatible with existing code base which has relied on a non-standard
<code>__proto__</code> property for a while. Duktape does not support the
<a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-__proto__-property-names-in-object-initializers">__proto__ property name in an object initializer</a>.</p>
<p>These custom features can be disabled with the feature options
<code>DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF</code> and
<code>DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY</code>.</p>
<h2 id="es6-proxy">Proxy object (subset)</h2>
<p>The Ecmascript E6 <code>Proxy</code> object allows property virtualization
and fine-grained access control for accessing an underlying plain object.
Duktape implements a strict subset of the <code>Proxy</code> object from
ES6. The following traps are implemented:</p>
<table>
<thead>
<tr><th>Trap</th><th>Implemented</th><th>Notes</th></tr>
</thead>
<tbody>
<tr><td class="propname">getPrototypeOf</td><td>no</td><td></td></tr>
<tr><td class="propname">setPrototypeOf</td><td>no</td><td></td></tr>
<tr><td class="propname">isExtensible</td><td>no</td><td></td></tr>
<tr><td class="propname">preventExtension</td><td>no</td><td></td></tr>
<tr><td class="propname">getOwnPropertyDescriptor</td><td>no</td><td></td></tr>
<tr><td class="propname">defineProperty</td><td>no</td><td></td></tr>
<tr><td class="propname">has</td><td>yes</td><td><code>Object.hasOwnProperty()</code> does not invoke the trap at the moment, <code>key in obj</code> does</td></tr>
<tr><td class="propname">get</td><td>yes</td><td></td></tr>
<tr><td class="propname">set</td><td>yes</td><td></td></tr>
<tr><td class="propname">deleteProperty</td><td>yes</td><td></td></tr>
<tr><td class="propname">enumerate</td><td>yes</td><td></td></tr>
<tr><td class="propname">ownKeys</td><td>yes</td><td><code>Object.keys()</code> enumerability check limitation, trap result validation (non-configurable properties, non-extensible target) not done</td></tr>
<tr><td class="propname">apply</td><td>no</td><td></td></tr>
<tr><td class="propname">construct</td><td>no</td><td></td></tr>
</tbody>
</table>
<p>Limitations include:</p>
<ul>
<li>Only about half of the ES6 traps have been implemented. This causes odd behavior
if you e.g. call <code>Object.defineProperty()</code> on a proxy object.</li>
<li><code>Object.keys()</code> invokes the <code>ownKeys</code> trap, cleans up the trap
result to a gap-free string list, but does not check that the property names returned
by the trap are enumerable. <code>Object.keys()</code> and <code>Object.getOwnPropertyNames()</code>
thus currently return the same value for a proxy object implementing the <code>ownKeys</code>
trap.</li>
<li>Proxy trap results are not validated, e.g. <code>ownKeys</code> trap result validation
steps described in <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys">[[OwnPropertyKeys]] ()</a>
for non-configurable target properties and/or non-extensible target object are not
yet implemented.</li>
<li>Proxy revocation feature of ES6 is not supported.</li>
<li>The target and handler objects given to <code>new Proxy()</code> cannot
be proxy objects themselves. ES6 poses no such limitation, but Duktape
enforces it to simplify the internal implementation.</li>
</ul>
<p>This custom feature can be disabled with the feature option
<code>DUK_OPT_NO_ES6_PROXY</code>.</p>
<h2 id="es6-typedarray">Typed arrays</h2>
<p>Duktape implements Khronos typed array support which is a subset of ES6
typed arrays. Support for typed arrays and Node.js Buffer can be disabled
with the feature option <code>DUK_OPT_NO_BUFFEROBJECT_SUPPORT</code>.</p>