* Fix Proxy.revocable() revoker function .name and .length properties
(empty name, 0 length).
* Summarize a revoked proxy as '[object RevokedProxy]' in internal readable
summary string, and add test coverage.
* Rename internal duk_push_class_string() as duk_push_objproto_tostring()
for clarity, the helper has Object.prototype.toString() semantics
(except when avoid_side_effects = 1).
* Fix duk_push_objproto_tostring() behavior for revoked Proxies, required
behavior is to throw (this happens in the @@toStringTag lookup which is
unconditional).
* Rename duk_get_top_index_unsafe() -> duk_get_top_index_known() for clarity.
* Add more duk_get_top_index_known() call sites when value stack is known
to have >= 1 entries.
* Rename duk_pop_unsafe() and variants to duk_pop_known() which is more
descriptive.
* Use duk_push_{undefined,tval}_unsafe() instead of direct valstack_top
manipulation in executor and a few other places.
* Add test coverage for chained Proxies in call setup.
* Minor code improvements.
* Implement Proxy.revocable() and add test case coverage for some
Proxy revocation basics.
* Fix revoked Proxy handling in instanceof and Array.isArray(), and
add test coverage.
* Fix revoked Proxy handling in call setup, and add test coverage.
Chained Proxies still not supported in call handling.
* Add stack top asserts for internal duk_prop_xxx.c file APIs:
defown, delete, enum, get, getown, has, ownpropkeys, set.
* Fix unused duk_hobject layouts from property table init code
in src-tools.
Switch to using WTF-8 for duk_hstring string representation. The main
differences to previous extended CESU-8/UTF-8 are: (1) valid surrogate
pairs are automatically combined to UTF-8 on string intern while invalid
surrogate characters are encoded in CESU-8, and (2) ECMAScript code always
sees surrogate pairs for non-BMP characters.
Together, these make it more natural to work with non-BMP strings for both
ECMAScript (which no longer sees extended codepoints as before) and native
code (which now sees valid UTF-8 for non-BMP whenever possible).
Internally the main change is in string interning which now always sanitizes
input strings (but no Symbols) to WTF-8. Also all call sites where the byte
representation of strings are dealt with need fixing. WTF-8 leads to some
challenges because it's no longer possible to e.g. find a substring with a
naive byte compare: surrogate characters may either appear directly (CESU-8)
or baked into a non-BMP UTF-8 byte sequence.
The main places where this needs complex handling include:
* charCodeAt / codePointAt
* Extracting a substring
* String .replace()
* String .startsWith() and .endsWith()
* String .split() and search functions (like .indexOf())
* RegExp matching
* String cache behavior
This commit fixes all the necessary sites with minimal baseline implementations
which are in some cases much slower than the previous CESU-8 ones. Further work
is needed to optimize the WTF-8 variants to perform close to CESU-8.
Rename duk_is_null_or_undefined() to duk_is_nullish() to better match
current ECMAScript terminology. Keep duk_is_null_or_undefined() as a
deprecated API macro. Add internal DUK_TVAL_IS_NULLISH().
* Fix Proxy behavior for Array.isArray() and duk_is_array(), when
argument is a proxied Array.
* Fix JSON serialization of proxied Arrays.
* Fix Object.prototype.toString() behavior for proxied Arrays.
Direct comparison may have portability concerns because a constant may
have more precision than its counterpart. Even a direct cast before
a comparison may not work (e.g. Math.atan2() assert with gcc -m32 still
fails even when both sides have an explicit double cast). So use an
internal always-inline helper for float/double comparisons, which also
allows -Wfloat-equal warning to be suppressed in a single helper; add
a clang pragma option so that both gcc and clang suppress the warning.
Other changes:
* Add -Wfloat-equal warning back to the Makefile.
* Fix all internal float comparison call sites to use the helper.
* Add code policy check for probable floating point comparison
(not very important with -Wfloat-equal enabled).
* Rework duk_heaphdr and subclass assertions into functions to
reduce debug build size.
* Add explicit object validity assert passes to mark-and-sweep.
This allows detection of invalid internal structures especially
when used with GC torture.
* Rename assertion macros for consistency, e.g. from
DUK_ASSERT_HSTRING_VALID to DUK_HSTRING_ASSERT_VALID.
* Add support for @@isConcatSpreadable in Array.prototype.concat().
* Remove DUK_USE_NONSTD_ARRAY_{CONCAT,MAP}_TRAILER config option support.
The concat option provided real world behavior for a specification "bug"
in ES5.1 but the bug has been fixed in ES2015. The map option was
unnecessary because ES5.0 already had the "non-standard" behavior.
* Change duk_bool_to to duk_small_uint_t from duk_small_int_t. This may
cause some sign warnings in calling code.
* Reject attempt to unpack an array-like value whose length is 2G or over;
previously was not checked explicitly, and the length was cast to duk_idx_t
with a sign change and the unpack would then later fail. Now it fails with
a clean RangeError.
* Add wrap check for Node.js Buffer.concat().
* API DUK_TYPE_xxx, DUK_TYPE_MASK_xxx, flag constants etc are now unsigned.
Both duk_hthread and duk_context typedefs resolve to struct duk_hthread
internally. In external API duk_context resolves to struct duk_hthread
which is intentionally left undefined as the struct itself is not
dereferenced. Change internal code to use duk_hthread exclusively which
removes unnecessary and awkward thr <-> ctx casts from internals.
The basic guidelines are:
* Public API uses duk_context in prototype declarations. The intent is to
hide the internal type, and there's already a wide dependency on the
type name.
* All internal code, both declarations and definitions, use duk_hthread
exclusively. This is done even for API functions, i.e. an API function
declared as "void duk_foo(duk_context *ctx);" is then defined as
"void duk_foo(duk_hthread *thr);".
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
Add minimal fast paths for Array.prototype operations like push() and pop(),
triggered when the 'this' binding is an Array which has its array part still
present. This is the most common case and user code will expect for example
Array.prototype.push() to be relatively fast.
The main purpose of this commit is to figure out the necessary internal
helpers for fast paths. More fast paths will be added separately.
Change handling of plain buffers so that they behave like ArrayBuffer
instances to Ecmascript code, with limitations such as not being
extensible and all properties being virtualized. This simplifies
Ecmascript code as plain buffers are just lightweight ArrayBuffers
(similarly to how lightfuncs appear as function objects). There are
a lot of small changes in how the built-in objects and methods, and
the C API deals with plain buffer values.
Also make a few small changes to plain pointer and lightfunc handling
to improve consistency with how plain buffers are now handled.
* Use shared error macros and shared error handler to reduce the size of call
sites of common errors.
* Make zero argument DUK_ERROR() calls non-vararg calls to reduce call site
footprint. Non-vararg calls have smaller call sites and because there are
a lot of call sites, this turns out to be significant.
* Remove variadic macros from internal DUK_ERROR() macro set and add separate
macros for argument counts 0 to 4; this is more portable and requires less
conditional code, and works well when a non-vararg call is used for most
error call sites.
* Rework macro / function argument order for the error path, try to keep 'thr'
in the same argument slot to avoid unnecessary register moves.
* Pack linenumber and error code into a single 32-bit argument when possible,
removes one more constant load from the call site.
* Convert some internal errors to RangeErrors when the underlying cause is an
implementation limit (such as a compiler temp limit) rather than an actual
unexpected internal situation.
* Simplify and share a few error messages to reduce string count.
* Add duk_require_function() and duk_require_callable() API calls
* Make duk_is_callable() a macro which calls duk_is_function()
* Include index for "invalid index" errors
* Add expected type and offending type/value for duk_require_xxx() errors
* Improve Array.prototype.forEach() and other iterator errors
Change a few built-ins to treat length as a 32-bit quantity
even though the specification allows some operations to extend
the Array length above 2^32-1. This is not very useful, because
it will be read back through ToUint32().
Add a C API binding for Object.defineProperty(): duk_def_prop().
In addition to Object.defineProperty() features, the API call provides a
"force" flag which allows properties to be added to non-extensible objects
and non-configurable properties to be changed (except virtual properties
which are immutable).
Because the name duk_def_prop() conflicts with internal calls, rename them
from duk_def_prop*() to duk_xdef_prop*(). This rename also makes it clearer
that the internal duk_xdef_prop*() calls have non-compliant, internal
semantics.
Also reimplement Object.defineProperty() and Object.defineProperties() (and
duk_def_prop()) so that they share the same internal helpers, and there is
no need for a temporary property descriptor object which is unnecessary churn.
Detailed changes:
- New helper to prepare (validate and normalize) property descriptors
- New helper to implement Object.defineProperty() internals, leaving
out validation of the property descriptor
- Reimplement Object.defineProperty() using the new helpers
- Reimplement Object.defineProperties() using the new helpers
- Reimplement duk_define_property() using the new helpers, so that a
temporary property descriptor object is no longer created
- Add support for "force" flag to Object.defineProperty()