The non-standard (default) variant allows non-BMP codepoints which get
encoded as extended UTF-8. The standard variant should use ToUint16()
coercion so that e.g. 0x123456 emits 0x3456.
The previous (buggy) code used ToUint32() + CESU-8 encoding in that case
which caused two codepoints (CESU-8) to be emitted for a codepoint (this
would actually be correct behavior for String.fromCodePoint()).
Fix the bug by using ToUint16() coercion when the standard behavior is
enabled.
Make duk_error_raw() noreturn but return void, and then define duk_error()
as a macro: (duk_error_raw(...), 0). This avoids MSVC warnings for duk_error()
being noreturn but still returning a value in its prototype.
Same changes for other throwers.
All Reflect functions specified in ECMAScript 2016 are implemented, and
most share Duktape/C helpers with their ES5 twins from Object.
* Reflect.apply()
* Reflect.construct()
* Reflect.defineProperty()
* Reflect.deleteProperty()
* Reflect.get()
* Reflect.getOwnPropertyDescriptor()
* Reflect.getPrototypeOf()
* Reflect.has()
* Reflect.isExtensible()
* Reflect.ownKeys()
* Reflect.preventExtensions()
* Reflect.set()
* Reflect.setPrototypeOf()
Presence of the Reflect object is controlled by DUK_USE_REFLECT_BUILTIN
and enabled by default in the standard configuration.
note: Reflect.enumerate() was retroactively removed in ES7, so it will
not be implemented in Duktape.
Add TextEncoder and TextDecoder built-ins, which allow Ecmascript code
to read and write text stored in ArrayBuffers. Based on the WHATWG
Encoding Living Standard:
https://encoding.spec.whatwg.org/#api
This avoids the need for a function call and up to two property lookups
for a `Math.pow()` invocation, as well as allowing expressions like
`2 ** 16` to be inlined at compile time.
Exponentiation uses the same internal handler as `Math.pow()`, per the
ES7 specification.
Usage:
x = base ** exp;
x **= 2;
Optimization to avoid a temporary for x <op>= y works for any RHS
which doesn't emit code when evaluated to an ivalue, e.g.:
* A plain constant or any expression which constant folds to a
constant, e.g.: x += 4 and x += 'foo' + 'bar'.
* A register-bound variable, e.g. x += y.
The optimization doesn't have enough state to detect safe cases
such as register bound 'y' in: x += y + 1.
Saves a few hundred bytes of footprint:
* duk_dup_0() = duk_dup(ctx, 0), duk_dup_1() = duk_dup(ctx, 1), etc.
* duk_dup_m2() = duk_dup(ctx, -2), etc.
* duk_dup_m1() is not added, because duk_dup_top() is the same thing