Post-ES5 features

Post-ES5 features

This page summarizes features implemented from ES2015 (ES6), ES2016 (ES7), and later. Custom features like Node.js Buffer and WHATWG Encoding API are also listed.

Many of the features can be disabled through config options such as DUK_USE_ES6_PROXY and DUK_USE_BUFFEROBJECT_SUPPORT.

Duktape status is also updated for new releases in kangax/compat-table.

Summary

Feature Specification Status Duktape
version
Notes
Duktape object Duktape n/a 1.0.0 Object providing Duktape specific operations like inspecting values, forcing a garbage collection run, etc.
Proxy object ES2015 Partial 1.0.0 Partial support, see separate Proxy trap support table below.
Object.setPrototypeOf() ES2015 Full 1.0.0 Object.setPrototypeOf() allows user to set the internal prototype of an object which is not supported in Ecmascript E5.
Object.prototype.__proto__ ES2015 Annex B Partial 1.0.0 Object.prototype.__proto__ is a setter/getter which provides the same functionality as Object.getPrototypeOf() and Object.setPrototypeOf() but is compatible with existing code base which has relied on a non-standard __proto__ property for a while. The property is not available for "bare objects". Duktape does not support __proto__ property name in an object initializer.
Additional RegExp syntax ES2015 Annex B Partial 1.0.0 Support for non-ES5 RegExp forms (most of them described in ES2015 Annex B) has been added incrementally over releases.
ArrayBuffer ES2015 Partial 1.3.0 Original Duktape implementation was based on the Khronos specification. Detached ArrayBuffers are not yet supported.
Typed arrays ES2015 Partial 1.3.0 Original Duktape implementation was based on the Khronos specification.
DataView ES2015 Partial 1.3.0 Original Duktape implementation was based on the Khronos specification.
Node.js Buffer Node.js v6.9.1 Partial 1.3.0 Original implementation was based on Node.js Buffer v0.12.1, current goal is Node.js v6.9.1 but not all methods are yet implemented. Duktape tracks the latest Node.js Buffer API.
const declaration ES2015 Partial 1.4.0 Support is partial, const is mostly just an alias for var except that an initializer is required: const variables are writable and function scope rather than block scope.
Computed property names ES2015 Partial 2.0.0 Computed method name in object literal not yet supported. Example: { [1+2]: 'three' }.
Octal number literal ES2015 Full 2.0.0 Example: 0o755. Legacy octal literals like 0755 are also supported.
Binary number literal ES2015 Full 2.0.0 Example: 0b10001010.
\u{H+} Unicode escape ES2015 Partial 2.0.0 The escape syntax is allowed in both string literals and identifier names. Not yet supported in RegExps (requires /u flag support which is not yet implemented). Non-BMP escapes decode to surrogate pairs. Example: "pile of \u{1f4a9}".
Reflect object ES2015 Partial 2.0.0 Provides access to several fundamental Ecmascript primitives as function calls. For example, Reflect.construct() behaves like new. Currently has some limitations, e.g. explicit newTarget is not supported in Reflect.construct().
ES2015 enumeration order ES2015 Full 2.0.0 Object.getOwnPropertyNames() follows the ES2015 OwnPropertyKeys enumeration order: (1) array indices in ascending order, (2) other properties in insertion order, (3) symbols in insertion order. While ES2015 or ES2016 don't require it, Duktape follows this same order also for for-in, Object.keys(), and duk_enum() in general. As in V8, the rule is applied for every "inheritance level" in turn, i.e. inherited non-duplicate properties always follow child properties.
Exponentiation operator ES2016 Full 2.0.0 Example: x ** y, x **= y.
RegExp getter lenience ES2017 draft n/a 2.0.0 RegExp.prototype.flags and other getters accept the RegExp.prototype object as a this binding without throwing a TypeError. See RegExp.prototype issues.
Symbol object ES2015 Full 2.0.0 Experimental, Symbol binding is disabled by default in Duktape 2.0.0, enable using DUK_USE_SYMBOL_BUILTIN.
Encoding API WHATWG Full 2.0.0 TextEncoder() and TextDecoder(), supports UTF-8 encoding.
"global" binding TC39 proposal Full 2.1.0 Experimental, named binding "global" for the global object. Disabled by default, enable using DUK_USE_GLOBAL_BINDING.
HTML comment syntax ES2015 Full 2.1.0 HTML comments syntax, recognizing <!-- and --> as specified in ES2015 Annex B.1.3.
new.target ES2015 Full 2.2.0 new.target syntax.
__defineGetter__, etc ES2017 Full 2.2.0 Annex B Object.prototype.{__defineGetter,__defineSetter__} and Object.prototype.{__lookupGetter__,__lookupSetter__}, also used in a lot of legacy code.
performance W3C Partial 2.2.0 W3C High Resolution Time API performance.now() with sub-millisecond resolution (when platform provides it).

Proxy handlers (traps)

The Ecmascript ES2015 Proxy object allows property virtualization and fine-grained access control for accessing an underlying plain object. Duktape implements a strict subset of the Proxy object from ES2015. Status of trap implementation:

Trap Implemented in version Notes
getPrototypeOf no
setPrototypeOf no
isExtensible no
preventExtension no
getOwnPropertyDescriptor no
defineProperty no
has 1.0.0 Object.hasOwnProperty() does not invoke the trap at the moment, key in obj does.
get 1.0.0
set 1.0.0
deleteProperty 1.0.0
enumerate removed The "enumerate" trap was removed in ES2016 and for-in uses "ownKeys" trap; Duktape 1.x supports "enumerate" trap in for-in.
ownKeys 1.0.0 Some trap result validation (non-configurable properties, non-extensible target) not yet implemented.
apply 2.2.0
construct 2.2.0 Some limitations for new.target and .prototype lookup.

Duktape specific behavior:

  • Proxy key argument is not string coerced at present, e.g. proxy[123] invokes the .get trap with a number (123) rather than a string ("123") key argument. Standard behavior is to string coerce the key which is much slower when virtualizing indexed objects. Future work is to change the behavior to conforming, but provide some way of configuring a Proxy to provide the sometimes preferred non-coercing behavior.

Limitations include:

  • Only about half of the ES2015 traps have been implemented. This causes odd behavior if you e.g. call Object.defineProperty() on a proxy object.

  • Proxy trap results are not always validated, e.g. ownKeys trap result validation steps described in [OwnPropertyKeys ](http://www.ecma-international.org/ecma-262/6.0/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys) for non-configurable target properties and/or non-extensible target object are not yet implemented.

  • Inheriting from Proxy objects does not always work correctly, e.g. get trap is not invoked when reading a property from an object inheriting from a Proxy.

  • Proxy revocation feature of ES2015 is not supported.

  • The target and handler objects given to new Proxy() cannot be Proxy objects themselves. ES2015 poses no such limitation, but Duktape enforces it for now to simplify the internal implementation.

Last edited by ,